# Android mobile device detection is too broad

**URL:** https://meta.discourse.org/t/android-mobile-device-detection-is-too-broad/41349
**Category:** Feature
**Created:** [March 21, 2016, 3:59am UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-broad/41349 "2016-03-21T03:59:09Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [March 21, 2016, 3:59am UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-broad/41349/1 "2016-03-21T03:59:09Z")

</div>

Continuing the discussion from [Android mobile device detection is too strict](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/22):

So…since @codinghorror’s change went through, Discourse now appears in mobile view for my 10" Samsung Galaxy Tablet (user agent below). According to the link shared in the linked post, Samsung Galaxy tablets currently take second place in for the US share of tablet visits. It has 7%, **up** from 6% a year before. This data shows 2 things that I think were overlooked: 1, Samsung tablet usage increased year over year, and 2, this is US only. When smartphone OS is looked at on a global scale, Android blows iOS away. I believe the last data from IDC showed Android at over 80%, so I would assume that tablet usage globally is greater than 7% (though still less than Apple).

Data aside, I think catching the second most used tablet is important. While avoiding a 100+ line regex statement is good, this one seems too short…

> Mozilla/5.0 (Linux; Android 5.0.2; SM-T800 Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.91 Safari/537.36

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 21, 2016, 4:08am UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-broad/41349/2 "2016-03-21T04:08:07Z")

</div>

According to:

> <https://stackoverflow.com/questions/5341637/how-do-detect-android-tablets-in-general-useragent/5344382#5344382>

> Mobile Android has “Mobile” string in the User-Agent header.

Adding `SM-T` into the user agent and `GT-P` makes me uneasy, I wonder if there are ANY examples in the wild of Android Mobile devices that don’t report the word `Mobile` in the user agent string.

Also, this is the recommendation by Google

[https://webmasters.googleblog.com/2011/03/mo-better-to-also-detect-mobile-user.html](https://webmasters.googleblog.com/2011/03/mo-better-to-also-detect-mobile-user.html)

> As a solution for mobile sites, our Android engineers recommend to specifically detect “mobile” in the User-Agent string as well as “android.”

To me the big question is, are there more 7’’ Android tablet (that are not ideal on the desktop theme) vs 9’'+ ones.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 21, 2016, 4:52am UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-broad/41349/3 "2016-03-21T04:52:08Z")

</div>

It is not even remotely the “second” most used tablet. The large tablet Android market is absolutely tiny and borderline irrelevant. The risk and harm to us as a company of not detecting the trillions of rando Android phone devices correctly as small screen “mobile” devices is severe.

I’ll need to check some user agents but if that ancient 2011 recommendation from Google is valid, to key off both Android and Mobile, that could be an option.

But if any percentage of Android phones, even 2 percent, is misdiagnosed by that change, the harm is far greater in terms of audience than the whole of the “tablet” android ghetto.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 21, 2016, 4:56am UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-broad/41349/4 "2016-03-21T04:56:34Z")

</div>

> [@codinghorror](#):
>
> But if any percentage of Android phones, even 2 percent, is misdiagnosed by that change, the harm is far greater in terms of audience than the whole of the “tablet” android ghetto.

I think the only risk is 7’’ tablets. Phones are safe.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 26, 2016, 9:16am UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-broad/41349/5 "2016-03-26T09:16:10Z")

</div>

All right, I’ve changed it to

```plaintext
user_agent =~ /Mobile/ && !(user_agent =~ /iPad/)

```

Let’s just say it’s a mobile device if it is telling us it is one:

`Mobile`

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 28, 2016, 9:21am UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-broad/41349/6 "2016-03-28T09:21:38Z")

</div>

This topic was automatically closed after 2 days. New replies are no longer allowed.
