Is there a way to detect if a user is on a mobile browser in Flambe?

333 views
Skip to first unread message

jt...@cricketmoonmedia.com

unread,
Jan 17, 2013, 6:13:00 PM1/17/13
to fla...@googlegroups.com
Hey, really enjoying working with Flambe and Flump! It would be great if I could detect if I was on a mobile or desktop browser. Mainly I need certain game play mechanics and directions to be slightly different between the two.

It looks like I could detect if it's html or flash by using preprocessor commands but I couldn't find anything for detecting which OS the user is currently on. Is there anything like that available?

Bruno Garcia

unread,
Jan 17, 2013, 7:22:31 PM1/17/13
to fla...@googlegroups.com
On 01/17/2013 03:13 PM, jt...@cricketmoonmedia.com wrote:
> It looks like I could detect if it's html or flash by using preprocessor commands but I couldn't find anything for detecting which OS the user is currently on. Is there anything like that available?

You can get mostly there by checking System.touch.supported, and if
true, assuming it's a mobile browser. (although, some laptops have touch
screens these days)

A System.os enum that returns Android, iOS, Windows, etc. would be
handy. Until then you could always scrape the user agent.

Bruno

jt...@cricketmoonmedia.com

unread,
Jan 17, 2013, 8:39:58 PM1/17/13
to fla...@googlegroups.com, b...@aduros.com
Thanks for the quick response! I think System.touch.supported will work just fine for what we need right now. Yeah, an OS enum would be great some time down the road.

bra...@seven2.net

unread,
Apr 19, 2013, 12:32:52 PM4/19/13
to fla...@googlegroups.com, jt...@cricketmoonmedia.com
I recently ran into a situation where I need to be able to distinguish between a touch-screen laptop, and a tablet or handheld. System.keyboard.supported returns true on Windows and IOS devices, even if there's no keyboard attached, so this can't be used to make the distinction.

I've been doing to experimentation with accelerometer support in Flambe. For games, this requires 3 sets of controls:

1. touch screen w/ accelerometer
2. touch screen w/o accelerometer
3. keyboard only

I default to accelerometer controls if present, and don't have any more to worry about there.

Microsoft Windows is the source of my difficulties since there is no accelerometer yet, and there's no way to tell if the browser is running on a mobile device. Windows Metro IE now runs Flash, and Flambe defaults to that, so I tried looking through the AS3 docs to see if there was a way to detect mobile, but found nothing. JS programmers used to detect ActiveX support to make the switch, but this is no longer possible.

On touch-screen laptops, I just settled for having the onscreen controls as well as keyboard controls for now.

bra...@seven2.net

unread,
Apr 19, 2013, 1:39:03 PM4/19/13
to fla...@googlegroups.com, jt...@cricketmoonmedia.com
Correction, in Flash on Windows Metro, System.keyboard.supported currently always returns false, in HTML, it always returns true. Seems like this is a bug.

Bruno Garcia

unread,
Apr 19, 2013, 3:27:35 PM4/19/13
to fla...@googlegroups.com
Yeah, last I checked it wasn't possible to detect keyboard or mouse
support in Javascript (using an "onkeydown" in window check).

In Flash, System.keyboard.supported should always have been returning
true as well. I just fixed this as there seems to be a reasonable way to
do detection there.

Bruno

mpa...@bkom.com

unread,
Apr 23, 2013, 11:32:32 AM4/23/13
to fla...@googlegroups.com, jt...@cricketmoonmedia.com
You could use JS functions as "navigator.useragent.match(/iPhone/i)", there's also (/iPod/i), (/iPad/i), (/Android/i) and maybe more.

But to do this I think you will need to communicate with the JS script as an external API.

bra...@seven2.net

unread,
Apr 23, 2013, 11:41:28 AM4/23/13
to fla...@googlegroups.com, jt...@cricketmoonmedia.com
Ya, but this breaks down on the Windows platform. I don't think there's a good way to know if Windows is running on a tablet or phone.

mpa...@bkom.com

unread,
Apr 23, 2013, 1:00:07 PM4/23/13
to fla...@googlegroups.com, jt...@cricketmoonmedia.com
Okay, I found something to detect Windows 8 with Touch enabled, but I wonder if Touch would be present on an All-In-One Touchscreen PC.

http://stackoverflow.com/questions/14226534/how-to-identify-if-user-agent-is-windows-8-tablet

more info on the different Windows User-Agent strings:
http://msdn.microsoft.com/en-us/library/ie/hh920767%28v=vs.85%29.aspx

I hope it helps you!

Akima

unread,
Jun 19, 2015, 2:16:40 PM6/19/15
to fla...@googlegroups.com, jt...@cricketmoonmedia.com
You could also use 'js.Browser.navigator.appVersion' (without need for external API).

Example of what that property returns:
5.0 (Linux; U; Android 4.2.2; es-es; SM-T111M Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30

I just found that and wanted to share... a couple of years late though xD

bra...@seven2.com

unread,
Jun 19, 2015, 5:14:17 PM6/19/15
to fla...@googlegroups.com, jt...@cricketmoonmedia.com
Actually now the issue is a little different because every modern HTML5 capable mobile browser supports accelerometer, including Internet Explorer 11 (but Flambe defaults to Flash in Windows ARM).

Using userAgent or appVersion strings to detect mobile is a broad topic, but for our purposes, it's pretty simple because our clients define what we support:

#if js
var userAgent = js.Browser.window.navigator.userAgent;
#end

#if flash
var userAgent = cast(System.external.call("function(){return navigator.userAgent;}"), String);
#end

var mobile = false;
var matches = ["Mini", "Mobile", "Android", "ARM", "Phone", "Tablet", "BlackBerry", "Palm", "webOS"];

for (match in matches)
{
if (userAgent.indexOf(match) > -1)
{
mobile = true;
break;
}
}

bra...@seven2.com

unread,
Jun 19, 2015, 5:36:21 PM6/19/15
to fla...@googlegroups.com, jt...@cricketmoonmedia.com
...And note "ARM" (all caps) in the matches array. That matches IE in Windows Metro (Microsoft Surface Tablet).

bra...@seven2.com

unread,
Jun 19, 2015, 6:04:27 PM6/19/15
to fla...@googlegroups.com, jt...@cricketmoonmedia.com
...And back to the issue of using System.touch.supported to detect mobile... Touch-screen laptops have become so common, some people even buy them without even knowing they have a touch screen. It's not a great user experience to throw accelerometer or touch controls at a laptop user.

So I'd almost say I'm in the camp that Flambe should have a specific check for this, except that including such a feature in Flambe may be complicated, since no test can be 100%, and every developer may have different needs from it...

...But it could be possible to make it customizable. 8-|

Mark Knol

unread,
Jun 20, 2015, 4:22:02 AM6/20/15
to fla...@googlegroups.com
So what is a laptop or desktop nowadays? A screen with keyboard and a mouse? A thing where you are in landscape mode? With windows or linux installed? I think you better adapt the design of your game according the features it has. Personally I also use a useragent check to see what is mobile, what is left could be considered as laptop/desktop etc, but it always feels as a loose check. Otherwise if you want to make sure, you could even ask the user.

Mark Knol

unread,
Jun 20, 2015, 4:22:03 AM6/20/15
to fla...@googlegroups.com

bra...@seven2.com

unread,
Jun 20, 2015, 5:49:49 AM6/20/15
to fla...@googlegroups.com
Are you saying it's a good idea to present a laptop user with touch screen controls?

bra...@seven2.com

unread,
Jun 20, 2015, 6:04:07 AM6/20/15
to fla...@googlegroups.com
Nm, I think I see what you're saying. I replied earlier with a 'soft' check that works for me. Is that much different from what you would use? I had to do some digging on the Googles through thousands of user agent strings to find all the right matches I thought would detect 99% of the devices we could target... But not everyone has spare moment during game development to do that, if they need it on-the-fly.

Peper Wesker

unread,
Nov 23, 2020, 1:45:32 PM11/23/20
to Flambe
Actually, I know the way how to do it! For example, it's a detect mobile browser with PHP! This is an effective PHP script that detects mobile phone browsers on your website! Check it out here:  http://detectmobilebrowsers.mobi/

суббота, 20 июня 2015 г. в 13:04:07 UTC+3, bra...@seven2.com:
Reply all
Reply to author
Forward
0 new messages