WordPress.org

Ready to get started?Download WordPress

Forums

PHP Browser Detection
How to detect Android Devices (3 posts)

  1. steckinsights
    Member
    Posted 2 years ago #

    Great plugin! This resource has been a huge help.

    How would one go about detecting an Android device? or other mobile device makers for that matter?

    I've tried is_mobile, but that does not seem to pinpoint Android devices. Any thoughts?

    http://wordpress.org/extend/plugins/php-browser-detection/

  2. steckinsights
    Member
    Posted 2 years ago #

    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.

  3. MartyThornley
    Member
    Plugin Author

    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic