How do detect Android Tablets in general. Useragent?
Mo’ better to also detect “mobile” user-agent
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.
Detecting Android device via Browser
< script language="javascript"> <!--
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) {
alert("MOBILE DEVICE DETECTED");
document.write("<b>----------------------------------------<br>")
document.write("<b>" + navigator.userAgent + "<br>")
document.write("<b>----------------------------------------<br>")
var userAgent = navigator.userAgent.toLowerCase();
if ((userAgent.search("android") > -1) && (userAgent.search("mobile") > -1))
document.write("<b> ANDROID MOBILE <br>")
else if ((userAgent.search("android") > -1) && !(userAgent.search("mobile") > -1))
document.write("<b> ANDROID TABLET <br>")
}
else
alert("NO MOBILE DEVICE DETECTED"); //--> </script>
@Carlos: In his article Tim Bray recommends this (as does another post by Google), but unfortunately it is not being applied by all tablet manufacturers.
... We recommend that manufactures of large-form-factor devices remove "Mobile" from the User Agent...
Most Android tablet user-agent strings I've seen use mobile safari, e.g. the Samsung Galaxy Tab:
Mozilla/5.0 (Linux; U; Android 2.2; en-us; SCH-I800 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
So at the moment I am checking on device names to detect Android tablets. As long as there are just a few models on the market, that's ok but soon this will be an ugly solution.
At least in case of the XOOM, the mobile part seems to be gone:
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
But as there are currently only tablets with Andorid 3.x, checking on Android 3 would be enough.
The issue is that the Android User-Agent is a general User-Agent and there is no difference between tablet Android and mobile Android.
This is incorrect. Mobile Android has "Mobile" string in the User-Agent header. Tablet Android does not.
But it is worth mentioning that there are quite a few tablets that report "Mobile" Safari in the userAgent and the latter is not the only/solid way to differentiate between Mobile and Tablet.