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?
Android – How to detect when an Android application is running in the emulator
androidandroid-emulator
Related Topic
- Android – Is quitting an application frowned upon
- Android – How to avoid concurrency problems when using SQLite on Android
- Android – How to you get the build/version number of your Android application
- Android – How to access the localhost from the Android device
- Android – How to “select Android SDK” in Android Studio
Best Answer
How about this solution (class implementation of
SystemProperties
is available here):Note that some emulators fake exact specs of real devices, so it might be impossible to detect it. I've added what I could, but I don't think there is a 100% way to detect if it's really an emulator or not.
Here a tiny snippet you can make in the APK to show various things about it, so you could add your own rules: