Add isMobile() method to Request class?

72 views
Skip to first unread message

wyz

unread,
Sep 17, 2010, 3:30:30 AM9/17/10
to play-framework
Hi, during my development with Play, I found it is good to add
isMobile() method to Request class, so we can detect whether user is
accessing from mobile browser or from desktop browser.

Thanks.

Pascal Voitot Dev

unread,
Sep 17, 2010, 4:26:42 AM9/17/10
to play-fr...@googlegroups.com
maybe something more generic would be more better ?
because we could have isTablet(), isBionicEye(), isBionicLeg(), isBionicArm() at the end...

;)


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


Federico Tolomei

unread,
Sep 17, 2010, 6:24:48 AM9/17/10
to play-fr...@googlegroups.com
Something that detect browser features would be more reliable, a la jQuery.

On Fri, Sep 17, 2010 at 9:30 AM, wyz <wangy...@gmail.com> wrote:

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
http://lupulu.li
skype: effe.to

grandfatha

unread,
Sep 17, 2010, 2:23:26 PM9/17/10
to play-framework
Browser features on the server side?

Federico Tolomei

unread,
Sep 17, 2010, 4:29:05 PM9/17/10
to play-fr...@googlegroups.com
It would be based on the User-Agent. Other frameworks to this, see [0] and [1].
I notice that ASP.NET have IsMobileDevice property :-)

[0] http://msdn.microsoft.com/en-us/library/system.web.httpbrowsercapabilities_properties.aspx
[1] http://php.net/manual/en/function.get-browser.php

On Fri, Sep 17, 2010 at 8:23 PM, grandfatha <dki...@googlemail.com> wrote:
> Browser features on the server side?

--
http://lupulu.li
skype: effe.to

Michael Boyd

unread,
Sep 17, 2010, 5:10:56 PM9/17/10
to play-fr...@googlegroups.com
The user agent doesn't tell you what browser features are available.

Federico Tolomei

unread,
Sep 18, 2010, 3:16:44 AM9/18/10
to play-fr...@googlegroups.com
Of course not directly. Those capability detector using pre-written
file (i.e. browsercap.ini in .NET/Mono). The User-Agent tells which
browser the client is using then some code loads a data structure with
property values for that User-Agent. See [0] [1]. Write a browsercap
can be complex task: Mono's browsercap is 16k rows and it is rather
complete (i.e. Emacs browser, zillion of crawlers...)

[0] http://www.koders.com/csharp/fid884EBD8E6ACB23CBF9B6EB6749DD54A5F3501C4F.aspx
[1] http://www.koders.com/csharp/fid8163466F4B976C002F3E48A11B62FCF43D955FF8.aspx

On Fri, Sep 17, 2010 at 11:10 PM, Michael Boyd <mic.t...@gmail.com> wrote:
> The user agent doesn't tell you what browser features are available.

--
http://lupulu.li
skype: effe.to

Nicolas Martignole

unread,
Sep 18, 2010, 6:08:41 AM9/18/10
to play-fr...@googlegroups.com
Hi

Sounds interesting

It wouldn't be too hard to propose a simple Java API
that takes a User-Agent String and returns a set of helpers
for instance.

Here is how I redirect my visitors on express-board.fr to a specific
controller when I detect iPhone :

public static void index() {
// some code removed here
// ........

Http.Header header = Http.Request.current().headers.get("user-agent");
if(header==null){
// this happens usually due to PHP security-break detector
robots that tries to
// find bugs on web site... yes it sucks I know
return;
}
if (header.value() == null) {
// drop bad client
return;
}

String headerValue=header.value().toLowerCase();

if (headerValue.contains("iphone")) {
redirect("IPhone/index");
return;
}

// ... some more code

}

Nicolas

2010/9/18 Federico Tolomei <federico...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages