18
\$\begingroup\$

I'm using LibGDX and flixel-android to build a Desktop/Android game. It feels like there should be a way of checking to see if you're currently being run on an Android device, the Desktop, and so on, but I can't find it anywhere. Am I supposed to just pass it down from the individual launchers? Surely LibGDX can just tell me?

\$\endgroup\$

2 Answers 2

37
\$\begingroup\$

I think you're after Application querying

switch(Gdx.app.getType()) {
   case ApplicationType.Android:
       // android specific code
   case ApplicationType.Desktop:
       // desktop specific code
   case ApplicationType.WebGl:
       /// HTML5 specific code
}
\$\endgroup\$
3
  • 4
    \$\begingroup\$ For reference: this has been changed to Gdx.app.getType() \$\endgroup\$
    – Amplify91
    Commented Sep 21, 2012 at 18:45
  • \$\begingroup\$ Can you detect whether it is Windows or Mac? \$\endgroup\$ Commented Aug 21, 2015 at 1:29
  • \$\begingroup\$ @LimThyeChean stackoverflow.com/q/228477/5771029 \$\endgroup\$
    – Winter
    Commented Mar 31, 2018 at 20:40
8
\$\begingroup\$

Magd's code may have worked at one stage, it didn't with my version of GDX, or certainly not my implementation anyway. I had to change it as follows:

switch(Gdx.app.getType()) {
       case Android:
           // android specific code
           TouchPadController.createTouchPad();
       case Desktop:
           // desktop specific code
       case WebGL:
           /// HTML5 specific code

}

\$\endgroup\$
1
  • \$\begingroup\$ What version is this? The latest nightly? \$\endgroup\$
    – ThorinII
    Commented Nov 1, 2013 at 12:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .