检测安装在真实设备中的Android应用程序?

时间:2018-12-17 11:40:03

标签: android android-emulator

我想检测我的应用程序安装在真实设备还是模拟器中? 如何检测到这一点? 我已经通过下面的链接 https://github.com/gingo/android-emulator-detector/tree/master/EmulatorDetectorProject

在上述条件下,很少有仿真器返回true,而很少有仿真器返回false(Memu https://www.memuplay.com/)。

能否请任何一个建议我介绍如何检测设备是模拟器还是设备?

注意:应用程序应可在没有Sim卡的平板电脑上使用。 预先感谢。

3 个答案:

答案 0 :(得分:0)

尝试此代码。这对我有用

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);
}

答案 1 :(得分:0)

我想您需要确定设备是否已植根:

/** @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();
        }
    }
}

使用“ su”命令可能不是一个好方法,如您在本页中所见:

Determine if running on a rooted device

答案 2 :(得分:0)

我使用以下代码,是从同一个问题(https://stackoverflow.com/a/32732674/7143587)中获得的。您还可以编写方法来检测其他模拟器。希望对您有帮助!

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");
    }