0

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

Thanks.

ashlar64
  • 954
  • 1
  • 7
  • 20

1 Answers1

0

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 Lu - MSFT
  • 8,163
  • 2
  • 5
  • 42
  • 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 Lu - MSFT May 01 '20 at 06:07