【问题标题】:device id in emulators模拟器中的设备ID
【发布时间】:2018-12-02 17:01:09
【问题描述】:

我可以仅从设备ID的信息来验证设备是真正的android设备还是模拟器?我读到如果你尝试在模拟器中获取值,你会得到 NULL,虽然我试过了,但每次都得到不同的值。

String android_id = Settings.Secure.getString(this.getContentResolver(),
                Settings.Secure.ANDROID_ID);

【问题讨论】:

    标签: android android-emulator identifier


    【解决方案1】:

    您可以检查系统属性用户类型 在大多数模拟器中它会返回“userdebug”,而在普通设备上会返回“user”

    注意:在某些根设备上,它也可能返回“userdebug”

    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;
    }
    

    【讨论】:

    • 好的,那么在这种情况下设备ID是无关紧要的吗?而且我想接近 100% 确定它是一个模拟器,即使它在我进行检查后已经扎根。
    • 是的,android_ID 或设备 id 是无关紧要的,你可以使用其他方法来更确定这样检查 "ro.build.product" 和 "ro.build.type" ,你需要使用 Nox 和genemotion 等许多模拟器检查结果。您可以在这里找到更多有用的信息:stackoverflow.com/questions/2799097/…
    猜你喜欢
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-24
    相关资源
    最近更新 更多