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