[SOLVED] What's the recommended way for a jME application to detect the current platform?

Hi there,

I’d like to change the behaviour of my application in some ways when it’s deployed to a mobile platform. Is there a recommended way to go about detecting the platform with jME?

One way I can accomplish this pretty reliably is by overriding AndroidHarnessFragment.onCreate in the subclass defined in the main activity and adding a “platform” setting, for instance. But I’m wondering how other people are doing it, and if there’s a tailored solution provided by jME that I may have missed.

A solution like using the os.name property (e.g. System.getProperty("os.name");) won’t work, since it’s “Linux” on Android (other properties might give it away, though - I didn’t check too extensively).

Thanks,
Brandon

There is no built in way to do this, no. I Never really had the need though, if you find a reliable way it could be added to the fragment code.

…maybe something like this could help…

    boolean this_is_Android; 
    try 
    { 
      Class.forName("android.app.Activity"); 
      this_is_Android = true; 
    } 
    catch (ClassNotFoundException e) 
    { 
        this_is_Android = false; 
    }

what does the os.arch (similar written) property display? arm something is a good indicator for android.

You could use JmeSystem.getPlatform() which returns a Platform enum.

public enum Platform {

    /**
     * Microsoft Windows 32 bit
     */
    Windows32,
    
    /**
     * Microsoft Windows 64 bit
     */
    Windows64(true),
    
    /**
     * Linux 32 bit
     */
    Linux32,
    
    /**
     * Linux 64 bit
     */
    Linux64(true),
    
    /**
     * Apple Mac OS X 32 bit
     */
    MacOSX32,
    
    /**
     * Apple Mac OS X 64 bit
     */
    MacOSX64(true),
    
    /**
     * Apple Mac OS X 32 bit PowerPC
     */
    MacOSX_PPC32,
    
    /**
     * Apple Mac OS X 64 bit PowerPC
     */
    MacOSX_PPC64(true),
    
    /**
     * Android ARM5
     */
    Android_ARM5,
    
    /**
     * Android ARM6
     */
    Android_ARM6,

    /**
     * Android ARM7
     */
    Android_ARM7,

    /**
     * Android x86
     */
    Android_X86,
    
    iOS_X86,
    
    iOS_ARM,
    
    /**
     * Android running on unknown platform (could be x86 or mips for example).
     */
    Android_Other;
    
    private final boolean is64bit;
    
    public boolean is64Bit() {
        return is64bit;
    }
    
    private Platform(boolean is64bit) {
        this.is64bit = is64bit;
    }
    
    private Platform() {
        this(false);
    }
}

On android the following implementation determines the platform.

    @Override
    public Platform getPlatform() {
        String arch = System.getProperty("os.arch").toLowerCase();
        if (arch.contains("arm")) {
            if (arch.contains("v5")) {
                return Platform.Android_ARM5;
            } else if (arch.contains("v6")) {
                return Platform.Android_ARM6;
            } else if (arch.contains("v7")) {
                return Platform.Android_ARM7;
            } else {
                return Platform.Android_ARM5; // unknown ARM
            }
        } else {
            return Platform.Android_Other;
        }
    }
2 Likes

Sure theres a built-in way?
http://javadoc.jmonkeyengine.org/com/jme3/system/JmeSystem.html#getPlatform()

1 Like

Sorry for the silly question but where is Linux ARM? The JOGL backend supports this “platform”.

jME doesn’t officially.

Thanks for the quick reply. I know that there are some developers here who ran JMonkeyEngine 3 on a Raspberry Pi 2.

oups, didn’t know

@DannyJo @normen That’s perfect, thanks! I mistakenly only used searched keywords against the Help index and not the Javadocs.

Personally I use vm name

boolean isAndroid = “Dalvik”.equals(System.getProperty(“java.vm.name”));

Rather look at “java.vendor”, it should be “The Android Project”, it works better even on very old versions of Android.

1 Like