11

I want to detect with javascript the native android browser (the one that comes installed on every android phone).

What should I look for in useragent ?

Arturo Volpe
  • 3,442
  • 3
  • 25
  • 40
Razvan
  • 710
  • 3
  • 9
  • 25
  • 1
    One size doesn't fit all. Some Android phone pretends itself as iPhone with iPhone's user agent. – Raptor Feb 05 '13 at 07:10
  • i don`t understand "feature detection" , can you please explain? – Razvan Feb 05 '13 at 07:13
  • 1
    [googling javascript android user agent](https://www.google.com/search?q=javascript+android+user+agent) - [googling js feature detection](https://www.google.com/search?q=js+feature+detection) – Trey Feb 05 '13 at 07:18
  • Feature detection doesn't work for *every* situation. If you check the user agent string for /Android/i you will have some luck, but that doesn't say what version of webkit it is. – nym Mar 12 '13 at 03:29

4 Answers4

16

This should work.

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));
PRASS
  • 315
  • 3
  • 7
8

Native browser, we could not detect at the first go itself, using the above mentioned code:

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));

as for most devices we got the following as the user agent for chrome browser:

enter image description here

and in the native browser:

enter image description here

And carried out this observation for Samsung Galaxy S3, htc desire, Asus Zenfone5.



And found out that the "Chrome/30.0.0.0" or the "chrome/" along withthe version is present for most devces including Zenfone 5, Samsung Galaxy s3. But the "version/" no. present in the user agent object is more than enough to differentiate the native and the Chrome.

We used the following code:

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

Hope, it's useful for you too... :)

Kailas
  • 7,350
  • 3
  • 47
  • 63
  • Is this still applicable to the native browser of Android 5.1.1? Because I can get as far as `var is_native_android = ua.indexOf("android") > -1 && ua.indexOf("mobile") && ua.indexOf('chrome') > -1` but all the other identifiers seem to fail. It looks like the native browser is using AppleWebkit - Mozilla/5.0. – cptstarling Mar 04 '16 at 14:41
  • This seems to be working on old as well as newer Android stock browsers. – dvlden Mar 09 '16 at 19:00
  • This won't work in Android 6.0.1 (at least not on my US T-mobile S6). Native Browser is now based on Chrome and it's really tough to tell the difference. The only difference I saw were manufacturer specific words (for me it said Samsung a couple times). My friend's S7 doesn't even have the native browser anymore, well Chrome is now the native browser for that phone. But the good thing is I guess it doesn't matter anymore since both _should_ be similar – Francisc0 Aug 19 '16 at 15:59
3

See this page for an overview of different user agent strings.

ellak
  • 2,531
  • 20
  • 26
-3

Try something like this:

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
  // Do something
}

or

check this url: http://davidwalsh.name/detect-android

Jamir Khan
  • 397
  • 1
  • 13