调用app

Posted znj211985

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了调用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 = ‘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 = "../images/share-brower.png";
	myImg1.style.display = "none";
	myImg2 = document.createElement(‘img‘);
	myImg2.style.width = "100%";
	myImg2.src = "../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");

  

以上是关于调用app的主要内容,如果未能解决你的问题,请参考以下文章

如何将字符串数据从活动发送到片段?

在 PopBackStack 之后片段弹出调用 OnViewCreated

javascript 用于在节点#nodejs #javascript内设置react app的代码片段

应用调试系统调用SWI

Android App 在片段中创建 ListView 引用时关闭

如何测量代码片段的调用次数和经过时间