In a support thread titled “My Android tablet was not detected as a mobile device,” user rahim123 reported that wide images on their 7" Android tablet (running Android 4.4.2) were not scaling correctly, requiring horizontal scrolling. They noted that the issue persisted in both the stock browser and mobile Firefox. codinghorror suggested using Google Chrome, as it is the supported native browser for Android 4.1+, and confirmed the layout worked correctly on their Nexus 7. rahim123 verified the issue in Chrome as well, showing a screenshot where images were chopped off.
codinghorror advised switching to mobile layout manually via the hamburger menu, which resolved the issue. rahim123 asked why their device wasn’t automatically detected as mobile. codinghorror explained that detection is limited to specific devices like the Nexus 7 due to the wide variety of Android tablets and ambiguous User-Agent strings. rahim123 provided their User-Agent string and suggested checking for the word “Android” or screen size parameters to improve detection.
User trident identified the root cause: the current regex for mobile detection fails because tablet Chrome User-Agent strings do not include the word “Mobile.” They proposed a regex update to better handle Android tablets and provided links to the relevant Discourse source code. sphism questioned why a responsive desktop style wasn’t used instead, but trident noted that a responsive approach was discussed previously and deemed less ideal at the time. Finally, rahim123 noted that Android 4.4 tablets no longer ship with Chrome by default, though the stock browser renders the mobile version correctly once manually enabled.
Hi, I noticed that on my 7" Android tablet, using the stock Android browser and also on mobile Firefox, the portrait version of topics with wide images aren’t scaling correctly, making it necessary to horizontally scroll. Here are a few examples:
We only support the native browser, and per our FAQ, only Android 4.1 or greater where Google Chrome is the default, native browser. Can you repro in Chrome?
Notice how the picture of the tablet in the review is chopped off. (Sorry about poor quality literal screenshot, real screenshots don’t work on my tablet and my good camera is broken atm.) By the way, it’s running Android 4.4.2.
–There’s a “Request desktop site” option in Chrome (and in Firefox) but it’s not checked.
Ah, the Discourse hamburger menu. I’ll be darned, there is an option, and that fixes it.
So now, the question is: Why doesn’t this device get detected as a mobile device?
I think we only detect the Nexus 7, because there are such a wide range of Android tablet devices, it’s unclear what the User-Agent would be that can cover all those tablets reliably.
Weird, I thought the user agent for mobile browsers was labeled as such. But for my tablet at whatsmyuseragent.com I’m just seeing “Mozilla/5.0 (Linux; Android 4.4.2; U25GT-C4WB Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Safari/5.37.36”. Quite ambiguous.
I’m not a developer, but would it be possible to:
Check for the presence of the word “Android” in the user agent and always offer the mobile version if present? It’s a pretty safe bet that most Android users are on a smaller screen.
Check the browser window size and offer the mobile version by default below certain parameters. The above mentioned whatsmyuseragent.com was able to correctly detect my screen resolution and browser window size.
Come to think of it, Discourse does seem to be able to somehow detect what is not a mobile browser, because on my desktop Firefox browser the Discourse hamburger menu does not even give me the option of using the mobile version.
It looks like the regex listed here should be applied here. Tablet chrome won’t include “Mobile” as a part of the user agent string; causing this check to fail.
(currently, this checks if the useragent contains “Mobile,” “webOS”, “Nexus 7” or does not contain “iPad”)
The ability to toggle mobile mode on and off seems to be determined here, but I’m not as sure on that one.
I’m not infront of something to test with for a little while, but I believe something like
Incidentally, it looks like Android KitKat 4.4 doesn’t come with Chrome by default anymore, according to:
My 4.4 tablet comes with a browser that renders the Discourse mobile version just as well as Chrome does once it’s enabled from the hamburger menu. Here’s the user agent: Mozilla/5.0 (Linux; Android 4.4.2; U25GT-C4WB Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Safari/537.36
Yeah the current approach seems sensible in that respect. I’ve just spent the last week theming a discourse site and was kinda confused why the mobile theme was totally separate. I ended up pulling in a few parts of the mobile templates to make a narrow desktop breakpoint, but it’s not ideal.