Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android execution in emulator or device?

Is there any way to know if my application is running on the emulator or on the device ?

like image 412
Arutha Avatar asked Feb 11 '10 15:02

Arutha


People also ask

How are apps executed in Android?

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.

What is Android device emulator?

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.

How can I run Android apps instead of emulator?

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.

Is an emulator used to run Android apps on computer?

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.


2 Answers

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;
}
like image 125
Ernie Avatar answered Sep 27 '22 17:09

Ernie


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.

like image 26
CommonsWare Avatar answered Sep 27 '22 18:09

CommonsWare