Run Android app on only on device not emulator

可紊 提交于 2020-02-25 04:32:05

问题


How to run android app only on device.

when app start check it launch on device or emulator. If it is emulator wanna app to stop.

how can i do this...


回答1:


In the onCreate() method of your launch activity, you can check whether the device is running on an emulator and, if it is, just call finish(). To check whether you're running on an emulator, you can use something like the following code (taken from this answer):

public static boolean isEmulator() {
    return Build.FINGERPRINT.startsWith("generic")
            || Build.FINGERPRINT.startsWith("unknown")
            || Build.MODEL.contains("google_sdk")
            || Build.MODEL.contains("Emulator")
            || Build.MODEL.contains("Android SDK built for x86")
            || Build.MANUFACTURER.contains("Genymotion")
            || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
            || "google_sdk".equals(Build.PRODUCT);
}

You can find lots of other suggestions on the web for detecting an emulator environment. I don't know of any that are absolutely foolproof, but the above is pretty robust.



来源:https://stackoverflow.com/questions/42686471/run-android-app-on-only-on-device-not-emulator

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