3

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.

2 Answers 2

11

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

1
  • iOS simulator returns nothing. Jan 9, 2015 at 10:12
1

You could use

Application#getType()

it will return one of the following outputs: Android, Applet, Desktop, iOS or WebGL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.