Android phone or Android tablet detection by http

2019-09-19 15:25发布

问题:

Is there a way to detect whether user is accessing your website from android powered tablet or phone on the server side?

I don't own any android devices, so it's not possible for me to test what kind of headers those devices send.

In my research I found: - many ways to detect it using javascript. But thats (IMHO) not the best moment, when you decide what web version should be sent to client. I prefer to server each version based on http headers sent by client. - database of http headers collected and sorted by device type. But can I rely on this? Also there are paid solution that can be more realibe, but I prefer free solutions.

Is there any other solution? Can you recommend one? And why?

回答1:

They mentioned this on the developer blog when tablets first came out:

http://android-developers.blogspot.com/2010/12/android-browser-user-agent-issues.html

The only difference is that "Mobile" is removed from the user agent.

Edit: These are the user agents for the Galaxy Tab and Flyer

Mozilla/5.0 (Linux; U; Android 3.1; en-us; GT-P7510 Build/HMJ37) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13

Mozilla/5.0 (Linux; U; Android 3.2.1; en-gb; HTC Flyer P510e Build/HTK75C) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13


回答2:

WURFL should do what you want.



回答3:

If you don't want to load the whole device db but still want more reliable matching, WURFL has a cloud product now (and it has a free offering that may be suitable for your needs):

http://www.scientiamobile.com/cloud