1

Is there a way to get the cellphone provider for Android or iOS?

Thanks.

ashlar64
  • 1,054
  • 1
  • 9
  • 24

1 Answers1

2

Agree with Jason, you can use dependencyService to achieve it.

First of all, create a interface in PCL.

    public  interface ICellphoneProvider
    {
        string GetCellphoneProvider();
    }

Use it with following code

string phoneProvider =DependencyService.Get<ICellphoneProvider>().GetCellphoneProvider();

Achieve the ICellphoneProvider interface in Android .

[assembly: Dependency(typeof(CellPhoneProviderService))]
namespace Xaminals.Droid
{
    class CellPhoneProviderService : ICellphoneProvider
    {
        public string GetCellphoneProvider()
        {
            Android.Telephony.TelephonyManager manager = (Android.Telephony.TelephonyManager)Android.App.Application.Context.GetSystemService(Context.TelephonyService);
            string carrierName = manager.NetworkOperatorName;
            return carrierName;

        }
    }
}

Please add android.permission.READ_PHONE_STATE permission in AndroidManifest.xml

Achieve the ICellphoneProvider interface in iOS .

[assembly: Dependency(typeof(CellPhoneProvideService))]
namespace Xaminals.iOS
{
    class CellPhoneProvideService : ICellphoneProvider
    {
        public string GetCellphoneProvider()
        {

            using (var info = new CTTelephonyNetworkInfo())
            {
                return info.SubscriberCellularProvider.CarrierName;
            }
        }
    }
}
Leon
  • 8,404
  • 2
  • 9
  • 52
  • Are there any update for this issue? If this reply is helpful, please mark it as answer(click the ✔ in the upper left corner of this answer), it will help others who have similar issue. – Leon May 01 '20 at 06:07