Android Question block app not to run on android virtual machine

acidorus

Member
Licensed User
Longtime User
Hello. Does anyone know if there is any way to configure the application to not run on android virtual machine
 

DonManfred

Expert
Licensed User
Longtime User
It uses JavaObject library

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Log($"Running in Emulator ${IsEmulator}"$)
End Sub
Sub IsEmulator As Boolean
    Private NativeMe As JavaObject
    NativeMe.InitializeContext
    Return NativeMe.RunMethod("isEmulator", Null)
End Sub

#if java
import android.os.Build;
public 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);
}
#End If
 
Upvote 0

acidorus

Member
Licensed User
Longtime User
where this code block is added

B4A:
#if java
import android.os.Build;
public 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);
}
#End If
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Which version of B4A are you using?

Inline Java is added in 4.3
 
Upvote 0

acidorus

Member
Licensed User
Longtime User
Hello @DonManfred good afternoon. Sorry for the delay to test this sample code .. but even though it is running on a virtual machine, it is returning me false. I'm using the Nox emulator for testing
 
Upvote 0
Top