0

I want to detect is My Application is installed in real device or Emulator? how can detect this? I have gone through the below linke https://github.com/gingo/android-emulator-detector/tree/master/EmulatorDetectorProject

With the above condition few emulators returning true, where as few emulators returning false(Memu https://www.memuplay.com/).

Could you please any one suggest me to how to detect the device is emulator or Device?

Note: App should work on tablets which doesn't have Sim card. Thanks in advance.

Chandramouli
  • 76
  • 1
  • 6

3 Answers3

0

Try this code. This works for me

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);
}
R4inV
  • 1
  • 1
0

i guess you need to determine if device is rooted or not:

/** @author Kevin Kowalewski */
public class RootUtil {
    public static boolean isDeviceRooted() {
        return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
    }

    private static boolean checkRootMethod1() {
        String buildTags = android.os.Build.TAGS;
        return buildTags != null && buildTags.contains("test-keys");
    }

    private static boolean checkRootMethod2() {
        String[] paths = { "/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
                "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
        for (String path : paths) {
            if (new File(path).exists()) return true;
        }
        return false;
    }

    private static boolean checkRootMethod3() {
        Process process = null;
        try {
            process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
            if (in.readLine() != null) return true;
            return false;
        } catch (Throwable t) {
            return false;
        } finally {
            if (process != null) process.destroy();
        }
    }
}

using "su" command may not be a good method as you can see in this page:

Determine if running on a rooted device

ygngy
  • 3,630
  • 2
  • 18
  • 29
0

I use the following code, got it from a same sort of question(https://stackoverflow.com/a/32732674/7143587). You could also write methods to detect other emulators. Hope it helps!

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");
    }
tijn167
  • 547
  • 2
  • 21