我已经看到很多从浏览器打开应用程序的解决方案,但不知道我做错了什么。实际上我需要通过链接打开我的应用程序(如果在用户设备上可用)。用户将通过短信获取链接,当他点击该链接时,我的java脚本代码将在用户设备中查找该特定应用程序(通过方案)。下面的代码在IOS中完美运行,但在android中没有。请帮忙。
我尝试从浏览器打开应用的网页链接代码:
var appStoreURL =" https://itunes.apple.com/us/app/workout-trainer/id395686735?mt=8&#34 ;;
//Check is device is iOS
var iOS = (navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false);
var appiOSUrlScheme = "myappscheme://" + window.location.search;
//alert(appUrlScheme);
var weblink="https://example/Home.net"
var AndroidStoreURL = "https://itunes.apple.com/us/app/workout-trainer/id395686735?mt=8";
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
var appAndroidUrlScheme = " myappscheme://" + window.location.search; ;
if (iOS) {
//If the app is not installed the script will wait for 2sec and redirect to web.
alert(appiOSUrlScheme);
var loadedAt = +new Date;
setTimeout(
function () {
if (+new Date - loadedAt < 2000) {
window.location = appStoreURL;
}
}
, 25);
//Try launching the app using URL schemes
window.open(appiOSUrlScheme, "_self");
}
else if (isAndroid) {
alert(appAndroidUrlScheme);
//If the app is not installed the script will wait for 2sec and redirect to web.
var loadedAt = +new Date;
setTimeout(
function () {
if (+new Date - loadedAt < 2000) {
window.location = AndroidStoreURL;
}
}
, 25);
//Try launching the app using URL schemes
window.open(appAndroidUrlScheme, "_self");
}
else {
//Launch the website
window.location = weblink;
}
</script>
Android Mainfest代码:
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.DEFAULT" />
<category
android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.VIEW" />
<data
android:pathPrefix="/Home"
android:scheme="myappscheme" />
</intent-filter>