Get a phone number on xamarin forms?

sagarsagar Member ✭✭

Hi, I am working on xamarin forms. How to detect a mobile number if dual sim means both I need to get.

Here is what I tried
Interface in shared project
public interface IDeviceInfo
{
string GetMyPhoneNumber();
}

Added class in an android project

public string GetMyPhoneNumber()
{
try
{
TelephonyManager mgr = Android.App.Application.Context.GetSystemService(Context.TelephonyService) as TelephonyManager;
return mgr.Line1Number;
}
catch (Exception ex)
{
throw;
}
}

When I am using android 5 it is returning the empty string and if i am using android 6+ it is giving permission error like Java.Lang.SecurityException: getLine1NumberForDisplay: Neither user 10286 nor current process hasandroid.permission.READ_PHONE_STATE, android.permission.READ_SMS, or android.permission.READ_PHONE_NUMBERS

And my manifest file is





Please help me to resolve this?

Answers

Sign In or Register to comment.