Pick up the Android version in the browser by Javascript
I can't comment because I don't have enough rep... Just wanted to add that I had to change neiker's code to
var match = ua.match(/Android\s([0-9\.]*)/i);
to make it case insensitive because the Galaxy S3 was returning "android" instead of Android in its user agent
function getAndroidVersion(ua) {
ua = (ua || navigator.userAgent).toLowerCase();
var match = ua.match(/android\s([0-9\.]*)/i);
return match ? match[1] : undefined;
};
getAndroidVersion(); //"4.2.1"
parseInt(getAndroidVersion(), 10); //4
parseFloat(getAndroidVersion()); //4.2
Use below code to get 2 digit version of Android
var ua = navigator.userAgent;
if( ua.indexOf("Android") >= 0 )
{
var androidversion = parseFloat(ua.slice(ua.indexOf("Android")+8));
if (androidversion < 2.3)
{
// do whatever
}
}
For example
Mozilla/5.0 (Linux; U; Android 2.2.1; fr-ch; A43 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
will return Android Version = 2.2