Question

I'm trying to retrieve the IMEI number of a phone. I'm using code below:

public static string GetDeviceId(Context context)
{
    TelephonyManager telephonyMgr = context.GetSystemService(Context.TelephonyService) as TelephonyManager;
    string deviceId = telephonyMgr.DeviceId == null ? "UNAVAILABLE" : telephonyMgr.DeviceId;
    return deviceId;
}

Is there any problem with the code? What else should I do?

Was it helpful?

Solution

You'll need to add the following permission in the manifest file

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top