-1

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.

  1. I tried on device and it returns Error.
  2. 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).
  3. I need the ID to be visible so before hand I can register it to my database to allow access to app's login.
Giant
  • 1,619
  • 7
  • 33
  • 67

2 Answers2

0

refer this you can find many other ways Is there a unique Android device ID?

  import android.provider.Settings.Secure;

 private String android_id = Secure.getString(getContext().getContentResolver(),
                                                    Secure.ANDROID_ID); 
Community
  • 1
  • 1
Manohar
  • 22,116
  • 9
  • 108
  • 144
  • i tried this id but as documentation says it will change when device is restored or rooted. and i dont want that one. also i have no way to get this ID so that i can register it unlike serial number where i can just go to `Settings > About Device > Status > Serial Number.` then store that value to database – Giant Nov 16 '16 at 08:46
  • refer that question , there are many other ways you can get the device id, check all answers once, atleast one of it should work – Manohar Nov 16 '16 at 08:47
  • I have only one question where can i see that value in device?I need to see it before hand so I can register it to my database. – Giant Nov 16 '16 at 08:54
  • in that question see +Seva Alekseyev answer , you can see that going to wifi->advanced MAC address – Manohar Nov 16 '16 at 09:00
  • i also tried this one problem is my MAC output is `02:00:00:00:00:00` which is not the MAC Address it the phone also i read somewhere that this will always be the output – Giant Nov 16 '16 at 09:18
0

You can use the combination of there phone number and IMEI number to get the unique Id. You can ask phone number to user and also device can show IMEI numbers. To get IMEI number and phone number programmatically do something like this.

TelephonyManager teleMan = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI number 
String imei = teleMan.getDeviceId();
//get The Phone Number
String phone = teleMan.getLine1Number();

Hope this solves it. Note :- I haven't tried this yet.

Nakul
  • 1,313
  • 19
  • 26