I saw one of my best question Is there a unique Android device ID?
Edited:
I need a solution for Android 10 too.
I used some following code to get Unique Id.
public static String getDeviceId(Activity context) {
PermissionsChecker checker = new PermissionsChecker(context);
if (checker.lacksPermissions(Manifest.permission.READ_PHONE_STATE))
PermissionsActivity.startActivityForResult(context, 0, REQUIRED_PERMISSION);
else {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice = tm.getDeviceId();
final String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32));
return deviceUuid.toString();
}
return null;
}
But I am getting some warning on hover on
tm.getDeviceId();
and
Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
as following:
Using getString to get device identifiers is not recommended.
Using device identifiers is not recommended other than for high value fraud prevention and advanced telephony use-cases. For advertising use-cases, use
AdvertisingIdClient$Info#getId
and for analytics, useInstanceId#getId.
Is there any solution? Is it harmful or anything else?
https://developer.android.com/training/articles/user-data-ids
– Cargian