很多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

Android Phone和Pad UA区别的更多相关文章

  1. Android SingleTask与SingleInstance的区别

    Android SingleTask与SingleInstance的区别 原文地址 现有2个项目,taskA.taskB.taskA负责调用taskB中指定的界面. taskB中有3个界面,a.b.c ...

  2. Xamarin.Form与Xamarin.Android或Xamarin.IOS的区别简述

    Xamarin.Form与Xamarin.Android或Xamarin.IOS的区别简述: 可能刚刚接触Xamarin的人来说,对于这个概念比较的模糊,认为这说的不都是同一个东西吗?事实并不是这样的 ...

  3. 【Bugly安卓开发干货】Android APP 高速 Pad 化实现

    Bugly 技术干货系列内容主要涉及移动开发方向.是由 Bugly 邀请腾讯内部各位技术大咖,通过日常工作经验的总结以及感悟撰写而成,内容均属原创.转载请标明出处. 怎样能在最快的时间内,实现一个最新 ...

  4. Android(四)-JVM与DVM区别

    JVM与DVM区别 1.由来 Android是基于java的既然java已经有了java虚拟机,为什么android还要弄一个DVM了?最重要的就是版权问题,一开始就是用的 JVM,没过多久就被SUN ...

  5. 【Bugly安卓开发干货分享】Android APP 快速 Pad 化实现

    项目背景 采用最新版本手机 APP(之后称为 MyApp)代码,实现其 Pad 化,为平板和大屏手机用户提供更好的体验.为实现 MyApp 的 Pad 化工作,需要我们首先来了解一下 MyApp 项目 ...

  6. Android Parcelable和Serializable的区别,androidparcelable

    本文主要介绍Parcelable和Serializable的作用.效率.区别及选择,关于Serializable的介绍见Java 序列化的高级认识. 1.作用 Serializable的作用是为了保存 ...

  7. [android界面]android中src和background区别——前景与背景

    ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸.src是图片内容(前 ...

  8. Android title和actionbar的区别

    我想在一个页面的顶端放入两个按钮,应该用title还是actionbar.他们两个什么区别?分别该什么时候用? 答: android title 是UI上的一小部分,它支持Text和Color,你可以 ...

  9. android:ImageView 和ImageButton的区别

    1.继承不同: java.lang.Object ↳ android.view.View ↳android.widget.ImageView ↳ android.widget.ImageButton ...

随机推荐

  1. 国内首篇介绍JanOS物联网操作系统的文章 - 如何把你的手机主板打造成物联网平台

    天地会珠海分舵注:如无意外,您现在正在看的将是国内首篇且是唯一一篇介绍炙手可热的物联网的操作系统JanOS的文章!不信你去百度!希望大家能喜欢.但本文只是引言,更多信息请还是访问JanOS的官网:ht ...

  2. CodeSmith 生成代码

    使用CodeSmith 生成代码 CodeSmith是一款优秀的代码生成工具.在ORM中,它能帮助我们生成实体类.XML配置文件,从而简化了我们一部分的开发工作.下面简要说说它的基本用法. 1.  打 ...

  3. Math.random引发的骗术,绝对是用随机数骗前端妹纸的最佳方法

    我觉得今天我运气特好,今天我们来赌一赌,我们来搞个随机数,Math.floor(Math.random() * 10),如果这个数等于0到7,这个月的饭,我全请了,如果是8或9,你就请一个礼拜成不?于 ...

  4. 分区表在安装系统(MBR)丢失或损坏

    操作系统能识别出硬盘中的各个不同的分区,是靠硬盘分区表(MBR)来识别的. 硬盘分区表中记录了各个分区的位置和大小以及类型等信息,假设这个分区表破坏了,那么这块硬盘里面的分区就会丢失.系统是无法在浏览 ...

  5. C# 截取图片区域,并返回所截取的图片

    /// <summary> /// 截取图片区域,返回所截取的图片 /// </summary> /// <param name="SrcImage" ...

  6. PHP 6:PHP 基本数据类型

    原文:PHP 6:PHP 基本数据类型 本章将介绍PHP基本类型.相信我们已经熟悉了C/C++,C#或者Java里的任意一种语言.本章会以C#为比较语言.OK,如果你想学PHP,你最先考虑的是什么呢? ...

  7. 1cocos2dx扩展UI控制,CCControlSlider,CCScale9Sprite(九妹图。),CCControlSwitch,CCControlButton

     UI控件来自cocos2dx的扩展库.完好了UI方面的元素,使cocos2dx更加丰富多彩.使用扩展库需包括: #include "cocos-ext.h" USING_NS ...

  8. Mac OSX操作系统安装和配置Zend Server 6教程(4)

    在前三节中,完成了安装和配置,最后是登录后台,并设置权限.Zend server后台登录默认端口是10081.浏览器中的的地址应输入http://localhost:10081/ZendServer. ...

  9. 如何用CSC.exe来编译Visual C#的代码文件

    原文:如何用CSC.exe来编译Visual C#的代码文件 C#的编译过程      如何用CSC.exe来编译Visual C#的代码文件   Csc.exe 编译器的位置路径:C:\Window ...

  10. 在weblogic11g发布该项目时遇到错误(不支持web-app_3_0)

    problem: cvc-enumeration-valid: string value '3.0' is not a valid enumeration value for web-app-vers ...