Skip to content

Instantly share code, notes, and snippets.

@dirkteucher
Last active August 29, 2015 14:11
Show Gist options
  • Save dirkteucher/a22a7a051c77aae2e26d to your computer and use it in GitHub Desktop.
Save dirkteucher/a22a7a051c77aae2e26d to your computer and use it in GitHub Desktop.
<!--Checking iOS version-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
Check android and iphone user agents<br>
<a href="calshow://"><button>iOS open callendar </button></a>
<br>
<br>
<a href="https://play.google.com/store/apps/details?id=cordproject.cord"><button>Android open application on </button></a>
<br>
<br>
<a href="market://details?id=cordproject.cord"><button>Android open directly through play store</button></a>
</body>
</html>
//Get android version
function getAndroidVersion(ua) {
ua = (ua || navigator.userAgent).toLowerCase();
var matchAndroid = ua.match(/android/);
if(matchAndroid){//yes this is an android device
alert(matchAndroid[0]);
//check Android version number greater than 4.4.4
matchAndroid = ua.match(/android\s([0-9\.]*)/);
if(matchAndroid[1] >= "4.4.1"){
alert(matchAndroid[1]);
}
}
}
var test = navigator.userAgent;
getAndroidVersion(test); //"4.2.1"
//parseInt(getAndroidVersion()); //4
//parseFloat(getAndroidVersion()); //4.2
//Check iphone
var iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
if(iOS){//yes this is an iPhone/iPod/iPad device
alert("This is an iphone ipad or ipod");
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
alert(v);
}
@dirkteucher
Copy link
Author

The start to a script to check iphone, ipad, ipod or android and what version is running then launch an app like callendar for iOS.

My current thinking is that an intent filter name is required in the link and on the app to be able to launch android apps.
http://appurl.org/docs/android
https://developers.google.com/app-indexing/webmasters/app
http://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment