安卓deeplink,跳轉(zhuǎn)react native頁(yè)面

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)了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容