0

In android from version 10 or API 29 . How can I get unique identification of device.

or how can I get the IMEI number from android 10

Jagjeet Singh
  • 204
  • 1
  • 2
  • 12

3 Answers3

2

If you just want unique identifier for your app instance, you can use.

Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID)

However this not unique device identifier, but for each app + user + device combination: As per the android docs

ANDROID_ID: On Android 8.0 (API level 26) and higher versions of the platform, a 64-bit number (expressed as a hexadecimal string), unique to each combination of app-signing key, user, and device.

For more information read this document from android dev and this stackoverflow discussion

Shiva
  • 543
  • 1
  • 6
  • 20
1

If you are supporting tablets which doesn't support calling functionality or doesn't have sim card slot then IMEI thing won't work for you try Instance Id https://developers.google.com/instance-id

or else if you can use Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID) returns a String. In Manifest

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Followed by generic code for permissions and once you have the required permission just do Build.getSerial();

Manoj Mohanty
  • 372
  • 2
  • 10
0

On Android 10, due to security concerns, third party apps cannot get the IMEI information anymore. You would need the app to have the android.permission.READ_PHONE_STATE permission, usually given to system applications.

With the permission granted, you can use something like this to get the device id which is more commonly used than IMEI

String serial;
    try {
        serial = Build.getSerial();
    } catch (SecurityException e) {
        // missing PHONE permission
        Log.e(LOG_TAG, "Could not get hardware serial number", e);
        serial = null;
    }
Chakson
  • 23
  • 8