Get Android Version using JS

Sometimes as a web application developer many of us need to apply some features or fixings based on Android OS version.

I use simple JS code which very simple and handy when I need to detect Android OS version.

function whichAndroidV() {
    var userAgent = navigator.userAgent.toLowerCase(); 
    var check = userAgent.match(/android\s([0-9\.]*)/);
    return check ? check[1] : false;
};

If you just call the function whichAndroidV() then you will get the android version like this 4.1.2, if it's not an android device then it'll return false;

comments powered by Disqus