Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict an APK not to get installed in Android Emulator/Simulator but in real device?

Hope you know that an application which is installed in an android device can be backed up and stored as an installable file(as an APK file) with the help of apps like Astro file manager. The same apk can be installed in the android simulator as well. So there is a chance that other can easily dig into the installed app's files like DB, shared preference, etc..

Is there any way to permit installing only in real device and not in simulators???

I know that if it is ROOTED device, we can access the app's data same like in the simulator. Even though i would like to know whether we can restrict installing apk in simulators.

Thanks in advance

like image 745
Madhu Avatar asked Apr 25 '13 11:04

Madhu


2 Answers

Use this function:

public static boolean isEmulator() {
    return Build.FINGERPRINT.startsWith("generic")
            || Build.FINGERPRINT.startsWith("unknown")
            || Build.MODEL.contains("google_sdk")
            || Build.MODEL.contains("Emulator")
            || Build.MODEL.contains("Android SDK built for x86")
            || Build.MANUFACTURER.contains("Genymotion")
            || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
            || "google_sdk".equals(Build.PRODUCT);
}

Therefor:

if (isEmulator()) {
   // emulator
} else {
   //not emulator
}

My recommendation:

try this from github.

Easy to detect android emulator

  • Checked on real devices in Device Farm (https://aws.amazon.com/device-farm/)
  • BlueStacks
  • Genymotion
  • Android Emulator
  • Andy 46.2.207.0
  • MEmu play
  • Nox App Player
  • Koplayer
  • .....

How to use with an Example:

EmulatorDetector.with(this)
                .setCheckTelephony(true)
                .addPackageName("com.bluestacks")
                .setDebug(true)
                .detect(new EmulatorDetector.OnEmulatorDetectorListener() {
                    @Override
                    public void onResult(boolean isEmulator) {

                    }
                });
like image 90
Saeed Avatar answered Sep 17 '22 18:09

Saeed


It's currently not possible to prevent APKs from being installed on a emulator. (it used to be possible by adding a sensor requirement to the app, but hese days emulators can emulate that too)

However, at runtime you should be able to validate if your app is running on a emulator using the following check:

if (android.os.Build.MODEL.equals(“google_sdk”)) {
   // emulator
} else {
   //not emulator
}

You could do this check before you create your DB and SharedPreference files etc.

like image 21
Leon Lucardie Avatar answered Sep 18 '22 18:09

Leon Lucardie