Is there any way to know if my application is running on the emulator or on the device ?
By default, every app runs in its own Linux process. The Android system starts the process when any of the app's components need to be executed, and then shuts down the process when it's no longer needed or when the system must recover memory for other apps.
The Android Emulator simulates Android devices on your computer so that you can test your application on a variety of devices and Android API levels without needing to have each physical device.
In the Android Studio toolbar, select your app from the run configurations drop-down menu. From the target device drop-down menu, select the device that you want to run your app on. Select Run ▷. This will launch the app on your connected device.
One popular way to get Android apps running on a PC is to go through the Android emulator released by Google as part of the official Android Studio. The emulator can be used to create virtual devices running any version of Android you want with different resolutions and hardware configurations.
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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With