I try to get my unique ID
IMEI
for Android 9.0 API LVL 28
When i tried with my code i have this error :
Java.Lang.SecurityException: getImeiForSlot: Neither user 10154 nor current process has android.permission.READ_PHONE_STATE.
public class DeviceInfo : IDeviceInfo
{
TelephonyManager telephonyManager;
public DeviceInfo()
{
telephonyManager =
(TelephonyManager)Application.Context.GetSystemService(Context.TelephonyService);
}
public string Id
{
get
{
telephonyManager = (TelephonyManager)Application.Context.GetSystemService(Context.TelephonyService);
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
// TODO: Some phones has more than 1 SIM card or may not have a SIM card inserted at all
return telephonyManager.GetMeid(0);
else
#pragma warning disable CS0618 // Type or member is obsolete
return telephonyManager.DeviceId;
#pragma warning restore CS0618 // Type or member is obsolete
}
}
and my androdManifest.xml
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
You have to :
Declare in the manifest that the application needs the READ_PHONE_STATE
permission. For a Xamarin project : right click on the project / Properties / Android manifest / Required permissions
Ask the user to grant the permission, see Runtime requests in the App permissions guide for more details.