问题
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