14

I need to offer slightly different app logic depending on the deployment platform my LibGDX app is running on, i.e. Desktop or Android, etc., does the LibGDX API offer a method of identifying the current runtime platform?

This post, "abstracting platform specific code in libGDX" offers a solution of sorts, I'm just wondering if there is something directly available in the API itself (?).

Big Rich
  • 5,864
  • 1
  • 40
  • 64

2 Answers2

17

You could potentially use Application#getType(), which will return one of the values defined by Application.ApplicationType:

  • Android
  • Applet
  • Desktop
  • iOS
  • WebGL
MH.
  • 45,303
  • 10
  • 103
  • 116
  • 1
    Another way to do it is to use an interface in the shared code section and resolve it differently in each of the sub projects. – AbstractChaos Jan 23 '14 at 13:22
17

If people are having trouble figuring out where you actually get the ApplicationType from, it's accessed from:

Gdx.app.getType()

And for a working example this would do:

if(Gdx.app.getType() == ApplicationType.iOS) {
    //Do awesome stuff for iOS here
}
Hamzah Malik
  • 2,540
  • 3
  • 28
  • 46
Nine Magics
  • 444
  • 4
  • 3