【调用app】敢说敢作敢为, 无怨无恨无悔。这篇文章主要讲述调用app相关的知识,希望能为你提供帮助。
//校验使用的应用 var browserCheck = { versions : function() { var u = navigator.userAgent; return { weixin : u.indexOf(‘MicroMessenger‘) > -1, // 微信 QQ : u.indexOf(‘MQQBrowser‘) > -1, // 是否QQ UC : u.indexOf(‘UCBrowser‘) > -1, // 是否UC Weibo : u.indexOf(‘Weibo‘) > -1, hw : u.indexOf(‘Huawei‘) > -1, // 是否华为 trident : u.indexOf(‘Trident‘) > -1, // IE内核 presto : u.indexOf(‘Presto‘) > -1, // opera内核 webKit : u.indexOf(‘AppleWebKit‘) > -1, // 苹果、谷歌内核 gecko : u.indexOf(‘Gecko‘) > -1 & & u.indexOf(‘Khtml‘) == -1, // 火狐内核 mobile : !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), // 是否为移动终端 ios : !!u.match(/\(i[^; ]+; ( U; )? CPU.+Mac OS X/), // ios终端 android : u.indexOf(‘Android‘) > -1 || u.indexOf(‘Linux‘) > -1, // android终端或者uc浏览器 iPhone : u.indexOf(‘iPhone‘) > -1 || u.indexOf(‘Mac‘) > -1, // 是否为iPhone或者QQHD浏览器 iPad : u.indexOf(‘iPad‘) > -1, // 是否iPad Macintosh : u.indexOf(‘Macintosh‘) > -1, // 是否Macintosh webApp : u.indexOf(‘Safari‘) == -1 // 是否web应该程序,没有头部与底部 }; }() }; // 安卓调起APP function androidHX(andrPath, andrDownloadPath) { // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为 // 否则打开a标签的href链接 var hasApp = true; var t1 = Date.now(); var ifr = document.createElement(‘iframe‘); ifr.src = https://www.songbingjia.com/android/‘scmcc://‘ + andrPath; ifr.style.display = ‘none‘; document.body.appendChild(ifr); window.setTimeout(function() { document.body.removeChild(ifr); var t2 = Date.now(); if (!t1 || t2 - t1 < 500) { hasApp = false; } }, 480); window.setTimeout(function() { if (!hasApp) window.location = andrDownloadPath; }, 1000); } //ios调起APP function applink(iosPath,iosDownloadPath){ document.location =‘SiChuanApp://‘ + iosPath; var clickedAt = new Date; setTimeout(function(){ !window.document.webkitHidden & & setTimeout(function(){ if(new Date - clickedAt < 2000){ window.location = iosDownloadPath; } }, 500); }, 500); } /** * 调起app如未安装跳转下载页面 * @param andrPath 安卓跳转路径 * @param iosPath ios跳转路径 * @param andrDownloadPath 安卓下载路径 * @param iosDownloadPath ios下载路径 */ function jumpAPPorDownload(andrPath, iosPath, andrDownloadPath, iosDownloadPath) { if (browserCheck.versions.android) { if (browserCheck.versions.weixin || browserCheck.versions.Weibo) { showAndr(); } else { androidHX(andrPath, andrDownloadPath); } } else if (browserCheck.versions.ios || browserCheck.versions.iPhone || browserCheck.versions.iPad || browserCheck.versions.Macintosh) { if (browserCheck.versions.webApp || browserCheck.versions.Weibo || browserCheck.versions.QQ) { showIos(); } else { applink(iosPath,iosDownloadPath); } } else { //window.location = pcPath; alert("未读取到手机系统信息"); } } var myDiv, myLabel, myImg1, myImg2, myDiv1; function initDialog() { myDiv = document.createElement(‘div‘); myDiv.style.display = "none"; myDiv.style.position = "fixed"; myDiv.style.top = "0%"; myDiv.style.left = "0%"; myDiv.style.width = "100%"; myDiv.style.height = "100%"; myDiv.style.backgroundColor = "black"; myDiv.style.zIndex = "1001"; myDiv.style.mozOpacity = "0.8"; myDiv.style.opacity = "0.8"; myDiv.style.filter = "alpha(opacity=80)"; myLabel = document.createElement(‘label‘); myLabel.style.width = "100%"; myLabel.style.height = "100%"; myImg1 = document.createElement(‘img‘); myImg1.style.width = "100%"; myImg1.src = "https://www.songbingjia.com/images/share-brower.png"; myImg1.style.display = "none"; myImg2 = document.createElement(‘img‘); myImg2.style.width = "100%"; myImg2.src = "https://www.songbingjia.com/images/share-safari.png"; myImg2.style.display = "none"; myDiv1 = document.createElement(‘div‘); myDiv1.style.display = "none"; myDiv1.style.width = "100%"; myDiv1.style.height = "100%"; // 添加子节点 myLabel.appendChild(myImg1); myLabel.appendChild(myImg2); myLabel.appendChild(myDiv1); myDiv.appendChild(myLabel); document.body.appendChild(myDiv); myLabel.onclick = function() { myDiv.style.display = "none"; myDiv1.style.display = "none"; myImg1.style.display = "none"; myImg2.style.display = "none"; }; }function showAndr() { if (myDiv == null) initDialog(); myDiv.style.display = "block"; myDiv1.style.display = "block"; myImg1.style.display = "block"; }; function showIos() { if (myDiv == null) initDialog(); myDiv.style.display = "block"; myDiv1.style.display = "block"; myImg2.style.display = "block"; }; function clickPartake() { jumpAPPorDownload("218.205.252.24:18081|scmccCampaign|flowMillionaire|index.html/2", "218.205.252.24:18081/scmccCampaign/flowMillionaire/index.html", "http://218.205.252.24:18082/files/appupd/scmcc_ATOP_7.apk", "https://itunes.apple.com/cn/app/si-chuan-yi-dongapp/id956438959?mt=8"); }
jumpAPPorDownload("218.205.252.24:18081|scmccCampaign|flowMillionaire|index.html/2",
"218.205.252.24:18081/scmccCampaign/flowMillionaire/index.html",
"http://218.205.252.24:18082/files/appupd/scmcc_ATOP_7.apk",
"https://itunes.apple.com/cn/app/si-chuan-yi-dongapp/id956438959?mt=8");
推荐阅读
- call和apply
- Ubuntu+IntelliJ IDEA+Android配置NDK环境+openCV
- Java字符串比较
- Java String类方法
- Java字符串valueOf()
- Java字符串trim()
- Java字符串toUpperCase()
- Java字符串toLowerCase()
- Java字符串toCharArray()