Use the user agent to identify security practices for the Android device type _android

Source: Internet
Author: User

As Android devices grow, many sites are starting to device Android devices, while Android's mainstream devices are mobile phones and tablets. Web site in the adaptation through the user agent (user agents, hereinafter referred to as UA) and how to distinguish it, this part of the content translated from Google's official blog Mo ' Better to also detect "mobile" user-agent.

Sharply

Standard judgment rule: Mobile Android has "mobile" string in the User-agent header. Tablet Android does not.
In the Android device UA string, the mobile device contains a mobile string, and the tablet device does not.

Erudite

Android is included in the UA string in the original Android device (that is, the phone), so you can use the Detect UA string to determine whether (case-insensitive) Android is included.

But then a new Android device appeared, the Android tablet, and unfortunately, the UA on the Android tablet also contains Android, which is better suited for displaying desktop (PC) Web layouts on the tablet. And if only by the above rules of judgment, the tablet users will not be very good user experience.

In view of the above problems, Google's Android engineers have proposed a solution. For devices that boot to a mobile layout, that is, a cell phone, you need to determine from the UA string whether to include both mobile and Android two words. Let's look at some examples first.

Like this UA string.

Copy Code code as follows:

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

Because there is no mobile in the UA string, it needs to be booted to a desktop layout (or a layout tailored to the Android big screen device). As we can see from this UA string, it comes from a large screen setting, Motorola's Xoom tablet.

We'll look at another UA string.

Copy Code code as follows:

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

Includes mobile and Android, so take this nexus one phone to the mobile layout.

I believe that by comparing the two UA strings above, you have found some commonalities in UA, let's look at these commonalities.

At last

So, when you're judging the Android phone device based on UA detection, check both Android and mobile two strings.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.