Sunday, May 8, 2011

Sniffing Android Tablets

On Android devices the "Mobile" string in the User Agent indicates that the device would prefer a version of the website optimized for Mobile (small form factor devices).
Tablets don't have this, for example

Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; device Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Safari/533.1

unlike phones

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


This can be used to detect Android tablet devices

is_androidmobile = request.user_agent =~ /android/i && request.user_agent =~ /mobile/i


in context

def is_mobile?
is_iosmobile = request.user_agent =~ /iphone|ipod/i
is_androidmobile = request.user_agent =~ /android/i && request.user_agent =~ /mobile/i

return is_iosmobile || is_androidmobile
end



more on that here,
android-browser-user-agent-issues

No comments:

Post a Comment