需求
5G短信消息中的链接需要点击调起APP,可先只支持Andriod 测试从H5调起App,如用户未装APP,则跳转下载页面。可先只支持Andriod
技术栈
ReactNative App
实现步骤
- Andriod包中设置支持brower打开(host/scheme可随意设置,后面使用这两个配置打开)
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="com.xxx" android:scheme="app" /> </intent-filter>
- 打安卓包
- 短信中配置链接
app://com.xxx/ - H5页面 需手动点击
<!DOCTYPE html>
<html>
<head>
<title>调起App</title>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
</head>
<body>
<div onclick="check()" id="check" style="font-size: 18px">
<i style="color: #469be9; font-style: normal">点击此处</i>
</div>
<script type="text/javascript">
function check() {
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
alert("暂不支持苹果系统");
} else if (navigator.userAgent.match(/android/i)) {
try {
window.location.href = "app://com.xxx/"; //schema链接或者universal link
window.setTimeout(function () {
window.location.href =
"https://downloadurlp="; //android下载地址
}, 3000);
} catch (e) {
alert(JSON.stringify(e));
}
}
}
</script>
</body>
</html>
常见问题
- 打包报错:glog-0.3.4/test-driver Couldn't follow symbolic link.
删除test-driver - MACBOOK(OSX)最升到11.0.1后android 打包报错 Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.
手动复制/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/tools.jar到/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib
sudo cp /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/tools.jar /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib