How to Detect When an Android Application Is Running in the Emulator

Can apps recognize that they run in an android emulator?

It is possible to get to know the details of the device your app is running on. From those details you can figure out, if the device is an Emulator or a physical device.
Please go through the link below and see Fingerprint, Manufacturer, Device, Model, Product.

https://developer.android.com/reference/android/os/Build.html

For example:
In your Splash Screen, if you put below code, then in your Logcat you should be seeing logs like below

`Log.e(TAG, "------------");
Log.e(TAG, "Device Values");
Log.e(TAG, "Fingerprint: " + Build.FINGERPRINT);
Log.e(TAG, "Brand: " + Build.BRAND);
Log.e(TAG, "Device: " + Build.DEVICE);
Log.e(TAG, "Manufacturer: " + Build.MANUFACTURER);
Log.e(TAG, "Model: " + Build.MODEL);
Log.e(TAG, "Product: " + Build.PRODUCT);

Real Device

2020-03-15 20:46:07.136 32602-32602/com.utkarshnew.android E/NewSplashScreen: ------------
2020-03-15 20:46:07.136 32602-32602/com.utkarshnew.android E/NewSplashScreen: Device Values
2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Fingerprint: iBall/iBall_Slide_Cleo_S9/iBall_Slide_Cleo_S9:8.1.0/OPM2.1710/47218:user/release-keys
2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Brand: iBall
2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Device: iBall_Slide_Cleo_S9
2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Manufacturer: iBall Slide
2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Model: iBall Slide Cleo S9
2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Product: iBall_Slide_Cleo_S9

Emulator

2020-03-15 20:53:44.725 6736-6736/com.utkarshnew.android E/NewSplashScreen: ------------
2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Device Values
2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Fingerprint: google/sdk_gphone_x86/generic_x86:10/QSR1.190920.001/5891938:user/release-keys
2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Brand: google
2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Device: generic_x86
2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Manufacturer: Google
2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Model: Android SDK built for x86
2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Product: sdk_gphone_x86`

If you see the above logs, you'll see that for Emulator the Device value will come as Generic, whereas for a physical device, it'll show the name of the device model.

Also, please see these links

How can I detect when an Android application is running in the emulator?

How to check Android app is running in real device or virtual device?

How to check Android app is running in real device or virtual device?

You can use checks like this:

public boolean isGenymotionEmulator(String buildManufacturer) {
return buildManufacturer != null &&
(buildManufacturer.contains("Genymotion") || buildManufacturer.equals("unknown"));
}

public boolean buildModelContainsEmulatorHints(String buildModel) {
return buildModel.startsWith("sdk")
|| "google_sdk".equals(buildModel)
|| buildModel.contains("Emulator")
|| buildModel.contains("Android SDK");
}

Detect if game running in android emulator

It's not easy to do since there are many emulators out there. The answer from this post says that you can use Build.FINGERPRINT.contains("generic") to do that.

You can port the Java code to C# in Unity with the AndroidJavaClass class and without building Java plugin. Below is the ported version in C#:

public bool IsEmulator()
{
AndroidJavaClass osBuild;
osBuild = new AndroidJavaClass("android.os.Build");
string fingerPrint = osBuild.GetStatic<string>("FINGERPRINT");
return fingerPrint.Contains("generic");
}

To make sure that this covers most emulator, use the android-emulator-detector plugin. This plugin seems to be rigorously tested and detects most emulators. You can use AndroidJavaClass to communicate with it and UnityPlayer.UnitySendMessage to make callback into your Unity code in C#.

Flutter: How to detect that the app is running on LD Player

The solution is to check for the existence of these folders, if any of them exists, then it is an LD Player.

'/storage/emulated/0/storage/secure',
'/storage/emulated/0/Android/data/com.android.ld.appstore'

I have implemented a method to take a list of folders paths and return true if any of them exists, which is the following:

bool anyFolderExists(List<String> foldersPaths) {
for (String folderPath in foldersPaths) {
if (Directory(folderPath).existsSync()) {
return true;
}
}
return false;
}

and I'm using it like this:

List<String> harmfulFoldersPaths = [
'/storage/emulated/0/storage/secure',
'/storage/emulated/0/Android/data/com.android.ld.appstore',
];

if(anyFolderExists(harmfulFoldersPaths))
{
print('LD Player Detected!');
}

Also I am using these two values from the output of device_info_plus package to decide that the app is working on an Emulator because they seems very generic:

"host": "ubuntu",
"device": "aosp",

I am using them like the following:

final androidInfo = await deviceInfoPlugin.androidInfo;

if (androidInfo.host == 'ubuntu' && androidInfo.device == 'aosp') {
print('LD Player Detected!');
}

But to be honest, I am afraid of this approach because I do not want to block any user by mistake, so I am using them with Firebase Remote Config to enable/disable it at any time but until now I am enabling them without any problem recorded.



Related Topics



Leave a reply



Submit