android execution in emulator or device?

放肆的年华 提交于 2019-12-21 05:06:16

问题


Is there any way to know if my application is running on the emulator or on the device ?


回答1:


I am using this code snippet which works on both Intel and ARM emulators:

if (Build.MODEL.contains("google_sdk") ||
    Build.MODEL.contains("Emulator") ||
    Build.MODEL.contains("Android SDK")) {
  RunsInEmulator = true;
}



回答2:


Secure.getString(getContentResolver(), Secure.ANDROID_ID); 

(where Secure is android.provider.Settings.Secure)

That value will be null on the emulator, non-null on devices.



来源:https://stackoverflow.com/questions/2245654/android-execution-in-emulator-or-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!