Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't detect Android in web server

The obvious way to detect Android by server is to search for "Android" string from User-Agent HTTP header. But - I've had complaints that this does not work on some devices (e.g. in my HTC Evo), they are not detected as Android. whatsmyuseragent.com gives for my HTC Evo 3D web browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.34 Safari/534.24 . No Android string or version. It could be a security software on the device who alters it it, or HTC-specific issue, not sure about it.

Obviously Android Chrome on same device has another, and better UA: Mozilla/5.0 (Linux; Android 4.0.3; HTC EVO 3D X515m Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19 , but I cannot just hope that e.g. QR Code reader app opens Chrome and not the built-in Android browser, which has invalid UA.

Is there a good trick (javascript call?) to detect reliably Android across devices and browsers?

Edit: looks like same issue with Galaxy S III, same User-Agent string: Android Phone Browser Detection

like image 522
JaakL Avatar asked Feb 01 '13 08:02

JaakL


3 Answers

It looks like I had selected "Show Desktop version" in Android web browser settings. Once turned off, the user-agent is with Android inside. This seems to be a feature of ICS, HTC is not to be blamed: google for the wrong user agent I've given to see that it happens on many different phones.

like image 181
JaakL Avatar answered Nov 20 '22 09:11

JaakL


For this particular task, I might suggest using wurfl server-side.

You can detect android by doing something very simple:

$requestingDevice = $wurflManager->getDeviceForHttpRequest($_SERVER);
if ($requestingDevice->getCapability("device_os") == "Android") {
    //the magic
}
like image 35
Aaron Saray Avatar answered Nov 20 '22 10:11

Aaron Saray


Checking the user agent has always been the recommended way to reliably determine the user's device, (at least with default settings anyway). Perhaps you could try making your search more robust? Mozilla suggests searching for the string "Mobi" instead.

like image 1
crazylpfan Avatar answered Nov 20 '22 09:11

crazylpfan