Reputation: 508
I have a core project that is converted to 5 different platforms. I need to change some parameters depending the platform that is running. For example if it's android I need to change the ip to the emulator localhost 10.0.0.2 and more.
I tried to determine this using the following answer In Java, is it possible to know whether a class has already been loaded?
but the invoking of any (even non existent) class returned true.
Upvotes: 3
Views: 634
Reputation: 7927
Application.getType() method returns the platform the app is currently running on:
switch (Gdx.app.getType()) {
case ApplicationType.Android:
// android specific code
break;
case ApplicationType.Desktop:
// desktop specific code
break;
case ApplicationType.WebGl:
// HTML5 specific code
break;
case ApplicationType.iOS:
//iOS specific code
break;
case ApplicationType.HeadlessDesktop:
//Headless desktop specific code
break;
case ApplicationType.Applet:
//Applet specific code
break;
default:
// Other platforms specific code
}
On Android, one can also query the Android version the application is currently running on:
int androidVersion = Gdx.app.getVersion();
Here is the official docs on the Application#ApplicationType Enum
Upvotes: 11
Reputation: 695
You could use
Application#getType()
it will return one of the following outputs: Android, Applet, Desktop, iOS or WebGL.
Upvotes: 1