Restricting running Android application on Android mobile emulator

Viewed 2668

I have an application which I wanted to running it on only physical devices, that means no virtual devices like Android emulator. If user tries to install or run it on emulator it must exit the application. Please provide restricting logic for the same. TIA

1 Answers

you can check whether the app is running on android emulator or not with this method. then if it is running on android emulator you can decide to finish activity (or whatever you decide)

fun isRunningOnEmulator(): Boolean {
    var result = (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"))
    if (result)
      return true

    result = result or (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))

    if (result)
      return true

    result = result or ("google_sdk" == Build.PRODUCT)

    return result
}

if this is not working you might want to give this library a try :

android-emulator-detector

if this library is old you might want to checkout this fork which also detects nox emulator

android-emulator-detector forked by daiwei92

Related