c# - Xamarin: How to get a phone number? -
i'm writing test application, on xamarin android. need know phone number. tried lot of options. last:
[assembly: xamarin.forms.dependency(typeof(phonenumberservice))] public string getmyphonenumber() { telephonymanager mgr = application.context.getsystemservice(context.telephonyservice) telephonymanager; return mgr.line1number; }
assemblyinfo.cs:
<`uses-permission android:name="android.permission.read_phone_state"/>`
androidmanifest.xml:
[assembly: usespermission(android.manifest.permission.readphonestate)]
on emulator works on phone not work. returns empty string.
how phone number?
to solve these problems,this link might you
try that:
telephonymanager mtelephonymgr; mtelephonymgr = (telephonymanager)getsystemservice(telephonyservice); var number = mtelephonymgr.line1number;
Comments
Post a Comment