1

Can I verify whether a device is a real android device or an emulator from only the information of the device ID? I read that you get NULL if you try to get the value in an emulator although I tried it and I get different values each time.

String android_id = Settings.Secure.getString(this.getContentResolver(),
                Settings.Secure.ANDROID_ID);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
muhzi
  • 119
  • 2
  • 14

1 Answers1

0

you can check the System Properties usertype in most emulators it will return "userdebug" and on normal devices will return "user"

NOTE : on some rooted devices it may return "userdebug" too

public static String getUserType() {
  String uType = "-"; 
  try {
      Class<?> c = Class.forName("android.os.SystemProperties");
      Method get = c.getMethod("get", String.class, String.class);
      uType = (String) get.invoke(c, "ro.build.type", "-");
  } catch (Exception ignored) {}
  return uType;
}
Somebody
  • 703
  • 1
  • 7
  • 23
  • OK, so the device id is irrelevant in this case? And I'd want to be close to100% sure it's an emulator even if it's rooted after I do the check. – muhzi Jun 23 '18 at 21:11
  • 1
    yes, android_ID or device id is irrelevant, you can use other methods with this to be more sure such checking "ro.build.product" with "ro.build.type" , and you need to check the results with many simulators such as Nox and genemotion etc. you may find more useful information here : https://stackoverflow.com/questions/2799097/how-can-i-detect-when-an-android-application-is-running-in-the-emulator – Somebody Jun 23 '18 at 22:32