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.

Community
  • 1
  • 1
serj
  • 508
  • 4
  • 20

2 Answers2

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

Nana Ghartey
  • 7,901
  • 1
  • 24
  • 26
1

You could use

Application#getType()

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

GenuinePlaceholder
  • 685
  • 1
  • 10
  • 25