I have 1 Solution run cross platform with 3 project (android, IOS and cross platform)
1. I created 1 inteface on Cross Platform Project
public interface IDeviceInfo {
string GetMyPhoneNumber();
}
2. On Adnroid Project i create 1 class IDeviceInfo with function
public string GetMyPhoneNumber()
{
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)Android.App.Application.Context.GetSystemService(Context.TelephonyService);
string Number = mTelephonyMgr.Line1Number.ToString();
TelephonyManager mgr = (TelephonyManager)Android.App.Application.Context.GetSystemService(Context.TelephonyService);
//Android.Telephony.TelephonyManager tMgr = (Android.Telephony.TelephonyManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.TelephonyService);
return Number;
}
3. On Cross Platform i add some code to get on file App.xaml.cs
public App()
{
InitializeComponent();
Context ct = Android.App.Application.Context;
string numbers;
var deviceInfo = Xamarin.Forms.DependencyService.Get<My_Name_Space.IDeviceInfo>();
var number = deviceInfo.GetMyPhoneNumber();
Toast.MakeText(ct, number, ToastLength.Long).Show();
MainPage = new Main_Page();
}
I config on cross platform and android project have permission (READ_PHONE_STATE, READ_PHONE_NUMBERS)
Build and deloy on Xiaomi Redmi 5A then run it can't get phone number.
Please guide e how to get it from android and IOS.