LibGDX – Check if currently on Android/Desktop

| | August 10, 2015

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?

2 Responses to “LibGDX – Check if currently on Android/Desktop”

  1. 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
    }
    
  2. James Stoddern on November 30, -0001 @ 12:00 AM

    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
    

    }

Leave a Reply