Big Rich
Big Rich

Reputation: 6025

How to determine which platform the current app is running on in LibGDX?

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 (?).

Upvotes: 15

Views: 6440

Answers (2)

Nine Magics
Nine Magics

Reputation: 444

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
}

Upvotes: 18

MH.
MH.

Reputation: 45493

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

  • Android
  • Applet
  • Desktop
  • iOS
  • WebGL

Upvotes: 17

Related Questions