0

My current goal is to know when an iPhone, Android, and some other specific device is accessing my Java web application. I do not have to know anything more specific than that. I know one can get the User-Agent from the HTTP Request header and do a string search on it.

Can it be as easy as just seeing if "iPhone" or "Android" is in the string? Looking at the user-agent information on wikipedia, it seems simple enough for my needs.

I have also looked at WURFL. However, it seems much more than I need. Plus, the APIs are GPL and I want my license to not be GPL. Thanks!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
finneycanhelp
  • 9,018
  • 12
  • 53
  • 77

3 Answers3

1

Yes, the results are needed for real-time processing. If it's a mobile device I support, I want to send them to another page.

Because...? Of a different and simpler style/look'n'feel? Use the CSS media rule for this.

<link rel="stylesheet" href="default.css" media="screen, projection">
<link rel="stylesheet" href="mobile.css" media="handheld">

Handhelds will pick the one for handheld. You can then just supply a different CSS which shrinks/rearranges sections or omits certain space-consuming sections, et cetera.

No need for nasty server-side user agent sniffing here.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

If you don't want a lot of granularity, search for a simple string like iPhone or Android in the user agent could be fine.

Just remember that user agent strings are completely arbitrary and nothing prevents somebody from changing the string to anything they want. Most people won't, especially on a mobile device, but keep that in mind when using the statistics that you generate.

Also, for example according to this the iPad user agent string is

Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us)
AppleWebKit/531.21.10 (KHTML, like Gecko)
Version/4.0.4 Mobile/7B314 Safari/531.21.10

Which means that if you just search for iPhone you will catch all the iPads in that bucket.

Another approach worth considering (if you don't need the results in real time) is to just log all the accesses to you app in a log together with the user agent string and use a log analysis tool to get you the data you need.

Community
  • 1
  • 1
martineno
  • 2,623
  • 17
  • 14
0

See Spring-Mobile project. You can use WurflDeviceResolver which detects almost all mobile devices

Vivek
  • 118
  • 1
  • 6