24

it's easy to detect the Android device, but I am having trouble detecting ONLY the Android native browser. Problem is the Dolphin browser has an almost identical user-agent string, and I'd like a way to know if they are using the native browser or not..

Is this possible?

8
  • possible duplicate of Auto detect mobile browser (via user-agent?) Commented Feb 15, 2012 at 1:45
  • 5
    I don't think so? that's a general strategy. This for JUST the native browser on Android 2.X, 3.X, 4.X Commented Feb 15, 2012 at 2:56
  • zytrax.com/tech/web/mobile_ids.html You should be able to catch the user agent, maybe the distro as well. But as with Android this looks to be easily configurable Commented Feb 15, 2012 at 3:32
  • thanks for the link, its an interesting read but I don't think it helps me. There's stuff in there about Dolphin but it's not going to be accurate enough to help. It's a shame, I think there is no user-agent methodology to identify between Dolphin on Android 2.x and Android 2.x native. The only way I can now think of, is that Dolphin's header is effectively twice as tall as the natives so could figure that out. Commented Feb 16, 2012 at 20:35
  • you could use target-dpi media queries that only android supports, but they have been deprecated so that may not be optimal for future versions Commented Mar 11, 2013 at 7:17

5 Answers 5

19

you simply need to test a few parts of the user agent string in order to make sure you have the default android browser:

var nua = navigator.userAgent; var is_android = (nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1); 

you can use the following to ensure that you do not match chrome within android, although on a lot of devices now, chrome is being used as the default browser.

var nua = navigator.userAgent; var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1)); 

EDIT: If you want to protect against case sensitivity, you can use the following:

var nua = navigator.userAgent.toLowerCase(); var is_android = ((nua.indexOf('mozilla/5.0') > -1 && nua.indexOf('android ') > -1 && nua.indexOf('applewebkit') > -1) && !(nua.indexOf('chrome') > -1)); 
Sign up to request clarification or add additional context in comments.

7 Comments

This will return true even for Chrome browser in Android?
That doesn't seem to be the case. I have a Samsung Galaxy S3 running android 4.1.2 and the default browser is the android browser (not chrome).
sometimes useragent returns AppleWebkit (lowercase on kit) and this fails: ua.indexOf('AppleWebKit') > -1. Probably best to do a regex instead of indexOf.
This will work with regex var nua = navigator.userAgent; var is_android = ((nua.match(/Mozilla\/5\.0/gi) !== null && nua.match(/Android/gi) !== null && nua.match(/AppleWebKit/gi) !== null) && (nua.match(/Chrome/gi) !== null)); PS How to make new line? Two spaces doesn't work :/
this did not detect the default android browser for Samsung Galaxy S5 (4.4.2)
|
2

I think you are searching for this:

Android native browser not updated above version 534.30 so you can filter to the version and Android UA string combination (above we can presume its a Chrome browser)

Here's my sample JavaScript code:

(If you need specific styling I would add a class to the body with the following JS snippet)

var defectAndroid = $window.navigator && $window.navigator.userAgent.indexOf('534.30') > 0 && $window.navigator.userAgent.toLowerCase().match(/android/); if (defectAndroid) { // sample code specific for your Android Stock browser } 

(Some Android devices reporting 'android' that's why we need the lower case conversation)

3 Comments

what if the version is 533.1 like in Android GingerBread? This would fail though.
Meanwhile I found this there is no clear answer for this Check this out: slides.com/html5test/the-android-browser#
@PeterM, Thanks for the link to those slides, you just ruined my day ;)
2

On a Galaxy S3, I found that both Chrome and the native browser had 'AppleWebkit' so I took that piece out of my conditional statement. I also added Version as that only appears in the native browser is seems. It works for me as

var ua = navigator.userAgent; var isAndroidNative = ((ua.indexOf('Mozilla/5.0') > -1) && (ua.indexOf('Android') > -1) && !(ua.indexOf('Chrome') > -1) && (ua.indexOf('Version') > -1)) 

3 Comments

YES - this is the only actually correct answer. All of the others assume Chrome is not mentioned in the UA - which is not true.
Unfortunately it did'nt work on Samsung S5 Mini Android 4.4.2 because there was "Chrome" in the user agent string when using the Android Default Browser...
...and on Samsung Galaxy Note S3 there is no "Version" string
-7
var ua = navigator.userAgent.toLowerCase(); var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile"); if(isAndroid) { // Do something! // Redirect to Android-site? window.location = 'http://android.davidwalsh.name'; } 

1 Comment

This just detects Android in general, not differences between different browsers available on Android (which was what the original question was looking for).
-11

You can do this with Javascript and the useragent feature. What u need to do is to make 2 If-requests:

First you detect the device type:

If android, ios, mobile, ipad, iphone Take this setting 

Now you make as much as u need if-requests or a case-request to detect the type of browser

If chrome, firefox, safari and so on Take this setting 

Thats it in the theory :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.