Detect Android Device using Javascript and PHP
by Sasikumar[ Edit ] 2014-05-19 15:39:42
Javascript
To detect android device using javascript use the following code,
var myUserAgent = navigator.userAgent.toLowerCase();
var isAndroidDevice = myUserAgent .indexOf("android") > -1 && myUserAgent .indexOf("mobile");
if(isAndroidDevice ) {
// Do something for android device
window.location = 'myandroid site url';
}
PHP
To detect android device using PHP use the following code,
$myUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(stripos($myUserAgent ,'android') !== false) && stripos($ua,'mobile') !== false)
{
header('Location: myandroid site url');
exit();
}