很多Android开发者或者网站端都可能会困扰关于如何区分Android phone和Android Pad的ua。确实这个问题很困难,我也曾被困扰了一段时间,后来在Stackoverflow中发现了解决方法。

答案:

Mobile Android has “mobile” in the User-agent. Tablet Android does not.


详细英文解释:

Here’s a trending User-Agent detection misstep we hope to help you prevent: While it seems completely reasonable to key off the string “android” in the User-Agent and then redirect users to your mobile version, there’s a small catch… Android tablets were just released! Similar to mobile, the User-Agent on Android tablets also contains “android,” yet tablet users usually prefer the full desktop version over the mobile equivalent. If your site matches “android” and then automatically redirects users, you may be forcing Android tablet users into a sub-optimal experience.

As a solution for mobile sites, our Android engineers recommend to specifically detect “mobile” in the User-Agent string as well as “android.” Let’s run through a few examples.

With a User-Agent like this:
Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13
since there is no “mobile” string, serve this user the desktop version (or a version customized for Android large-screen touch devices). The User-Agent tells us they’re coming from a large-screen device, the XOOM tablet.

On the other hand, this User-Agent:
Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
contains “mobile” and “android,” so serve the web surfer on this Nexus One the mobile experience!

While you may still want to detect “android” in the User-Agent to implement Android-specific features, such as touch-screen optimizations, our main message is: Should your mobile site depends on UA sniffing, please detect the strings “mobile” and “android,” rather than just “android,” in the User-Agent. This helps properly serve both your mobile and tablet visitors.

注意,某些设备可能稍有问题,并没有按照上述的标准实施。

相关文章链接:http://googlewebmastercentral.blogspot.com/2011/03/mo-better-to-also-detect-mobile-user.html

http://webcache.googleusercontent.com/search?q=cache:2hokPrP-0FUJ:stackoverflow.com/questions/5341637/how-do-detect-android-tablets-in-general-useragent+&cd=2&hl=zh-CN&ct=clnk&gl=cn


更多相关文章

  1. 推荐阅读:Android开发者的博客
  2. GitHub最火的android 项目
  3. android底层开发!双非渣本Android四年磨一剑,offer拿到手软
  4. GitHub上优秀Android(安卓)开源项目
  5. 写给Android开发者的ThreadLocal介绍
  6. Android平台上的11个感应器你都知道吗
  7. Google I/O Android(安卓)相关演讲视频汇总
  8. Android开发者已经度过了初级、中级,如何成为一个Android高手呢?
  9. Android中文API合集(7) + 开发者指南合集(2) (chm格式)

随机推荐

  1. Android在标准linux基础上对休眠唤醒的实
  2. Android XML Pull解析
  3. android 资源和国际化
  4. Android(安卓)Studio错误Error:(23, 17)
  5. Android上的内存分配策略优化
  6. Android的崛起之路与束足之绳
  7. Android 怎样击败 iPhone ?
  8. Android(安卓)Studio 集成JPUSH推送
  9. 仿网易新闻效果源码分析
  10. 使用Tortoise SVN版本控制Android项目in