Support » Plugin: PHP Browser Detection » [Plugin: PHP Browser Detection] How to detect Android Devices

Viewing 2 replies - 1 through 2 (of 2 total)
  • I added this to “php-browser-detection.php” and it seems to work when viewing through my browser (using the User Agent/Developer settings for Android devices), but isn’t working on the phone:

    function is_android (){
    	$browserInfo = php_browser_info();
    	if (preg_match("/Android/", $browserInfo['browser_name_pattern'], $matches)) {
    		if ($version == '') :
    			return true;
    		elseif ($browserInfo['majorver'] == $version ) :
    			return true;
    		else :
    			return false;
    		endif;
    	} else {
    		return false;
    	}
    }

    This isn’t working, but I feel as if I’m on the right track. Any help is appreciated.

    Plugin Author MartyThornley

    (@martythornley)

    Whenever I add a new function to find a browser, I first try echoing the browser info to the screen and then find something that identifies that specific browser.

    Try using this…

    $browserInfo = php_browser_info();
    print '<pre>'; print_r( $browserInfo ); print '</pre>';

    Place that somewhere publicly visible like the page template in your theme. Then view the site on the different browsers and you should see the specific info for each. Then change that preg_match line to find it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: PHP Browser Detection] How to detect Android Devices’ is closed to new replies.