I'm looking for help to get the UUID of my Android phone. I have searched the net and found one potential solution but it is not working in the emulator.
Here is the code:
Class<?> c;
try {
c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ro.serialno");
Log.d("ANDROID UUID",serial);
} catch (Exception e) {
e.printStackTrace();
}
Does anybody know why it isn't working, or have a better solution?
This works for me:
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uuid = tManager.getDeviceId();
EDIT :
You also need android.permission.READ_PHONE_STATE
set in your Manifest. Since Android M, you need to ask this permission at runtime.
See this anwser : https://stackoverflow.com/a/38782876/1339179