美文网首页
安卓deeplink,跳转react native页面

安卓deeplink,跳转react native页面

作者: MasterPaul | 来源:发表于2020-02-29 16:35 被阅读0次

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中获取网页中传过来的值,使用的是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、写一个html测试

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script>

</script>

<h1>标题</h1>
<a href="zaiaapp://link/keyword/123/开火箭"> <h1>打开在啊APP</h1> </a> <br>

</body>
</html>

4、mac电脑可以使用自带的web服务器测试
把h5测试文件放到 /Library/WebServer/Documents 文件下面

  开启本地服务器:  sudo apachectl start

   重启本地服务器:  sudo apachectl restart

   关闭本地服务器:  sudo apachectl stop

手机浏览器输入电脑ip地址就能访问了

相关文章

网友评论

      本文标题:安卓deeplink,跳转react native页面

      本文链接:https://www.haomeiwen.com/subject/xexmhhtx.html