How can I detect when an Android application is running in the emulator?
I would like to have my code run slightly differently when running on the emulator than when running on a device. ( For example , using 10.0.2.2 instead of a public URL to run against a development server automatically.) What is the best way to detect when an Android application is running in the emulator?
一个常见的例子是Build.FINGERPRINT.contains("generic")
这个解决方案如何:
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);
}
那么Android ID不适合我,我目前正在使用:
"google_sdk".equals( Build.PRODUCT );
链接地址: http://www.djcxy.com/p/90534.html
上一篇: Android模拟器不需要键盘输入