var tMgr = (TelephonyManager)Forms.Context.ApplicationContext.GetSystemService(Android.Content.Context.TelephonyService);
return tMgr.Line1Number;
This code is returning null.
I want to generate this type of popup while registration image
var tMgr = (TelephonyManager)Forms.Context.ApplicationContext.GetSystemService(Android.Content.Context.TelephonyService);
return tMgr.Line1Number;
This code is returning null.
I want to generate this type of popup while registration image
Firstly , we need to add the permission in AndroidManifest.xml
<uses-permission android:name="READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
In Addition , Forms.Context
is obsolete after XF 2.5 . So we could use the plugin Plugin.CurrentActivity from nuget.
Simply call the Init method on OnCreate in MainActivity
CrossCurrentActivity.Current.Init(this, bundle);
And access it like following
var tMgr = (TelephonyManager)CrossCurrentActivity.Current.AppContext.GetSystemService(Android.Content.Context.TelephonyService);
return tMgr.Line1Number;