I have a samsung j5. I am using the Serial Number that can be found in
Settings > About Device > Status > Serial Number.
It has a value of RF8H933KWLF
which I assume to be unique. Now I register this value to my database and when I run my app I send a request to my database and check if the device I use is registered in my database. The way I get the Serial Number of device is:
String serialNumber = "";
try {
Class <? > c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class, String.class);
serialNumber = (String) get.invoke(c, "sys.serialnumber", "Error");
if (serialNumber.equals("Error")) {
serialNumber = (String) get.invoke(c, "ril.serialnumber", "Error");
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
For my device I can get a correct value.
My question is why when I use a different device I cant get the value that I see in the Serial Number
.
- I tried on device and it returns
Error
. - What could be an alternative ID I can use that is unique to a device (does not change even if device is restored or rooted).
- I need the ID to be visible so before hand I can register it to my database to allow access to app's login.