1、修改Manifest
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="${APP_NAME}"
android:windowSoftInputMode="adjustResize | adjustNothing" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="link"
android:scheme="zaiaapp"
/>
</intent-filter>
</activity>
2、React native中獲取網(wǎng)頁(yè)中傳過(guò)來(lái)的值,使用的是Linking的getInitialURL方法
Linking.getInitialURL().then((url) => {
if(!url){
return
}
if(url.startsWith('zaiaapp://link/')){
url = url.replace('zaiaapp://link/','')
console.log(url)
let components = url.split('/')
console.log(components)
if(components[0] === 'keyword'){
let param = {
userId:components[1],
keyword:components[2]
}
this.props.navigation.navigate('WordDetail',{data:param})
}
}
}).catch(err => console.error('An error occurred', err));
3、寫(xiě)一個(gè)html測(cè)試
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script>
</script>
<h1>標(biāo)題</h1>
<a href="zaiaapp://link/keyword/123/開(kāi)火箭"> <h1>打開(kāi)在啊APP</h1> </a> <br>
</body>
</html>
4、mac電腦可以使用自帶的web服務(wù)器測(cè)試
把h5測(cè)試文件放到 /Library/WebServer/Documents 文件下面
開(kāi)啟本地服務(wù)器: sudo apachectl start
重啟本地服務(wù)器: sudo apachectl restart
關(guān)閉本地服務(wù)器: sudo apachectl stop
手機(jī)瀏覽器輸入電腦ip地址就能訪問(wèn)了