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
For this particular task, I might suggest using wurfl server-side.
You can detect android by doing something very simple:
What I understood from your problem is you are getting user agent on some device and on few of the device refusing to give that. so i am assuming that you have a application on android device which is calling your server through some webservice and from that you are trying to extract the user agent. so what solution I can see here is in the android application add the user agent parameter as from code so it will be posted in the HTTP header and from server you can extract that easily
I had same problem but I resolved in this way.
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.
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.