xpenatan/gdx-teavm

How to distinguish between mobile and desktop browser?

Quillraven opened this issue · 1 comments

Hi,

I have a question: how do you distinguish between mobile and desktop browser?

I saw a code snippet like:

val userAgent = Window.Navigator.getUserAgent() ?: ""
if(userAgent.contains("Mobile") || userAgent.contains("Android")) {
  // mobile browser
}

but this does not seem to work because of missing GWTBridge class at runtime. Also, it is GWT stuff and I am not sure if this is the correct approach for TeaVM.

In LibGDX itself I only see an ApplicationType which always return WebGL for TeaVM backend. I think you cannot distinguish between mobile and desktop browser with that.

How would you solve that?

Hi. sorry for long delay. Very busy with work.

TeaWebAgent and TeaAgentInfo class check OS and browser. Maybe adding mobile and android will work.
https://github.com/xpenatan/gdx-teavm/blob/master/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/agent/TeaWebAgent.java

It just set as a system property in TeaApplication.init(). I guess this part of code needs improvements.