Is there a way to get the cellphone provider for Android or iOS?
Thanks.
Is there a way to get the cellphone provider for Android or iOS?
Thanks.
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;
}
}
}
}