我可以使用链接库通过react-native监听和处理IOS上的传入链接:https://facebook.github.io/react-native/docs/linking.html https://facebook.github.io/react-native/docs/linking.html,但它显示为 url 添加事件侦听器的功能是 IOS 平台特定的。是否有其他方法可以侦听 Android 上我的应用程序的传入链接并在 Javascript 端处理它?
我刚刚开始工作了!你只需要跟随这些说明 https://developer.android.com/training/app-indexing/deep-linking.html#adding-filters.
基本上,添加一个<intent-filter>
根据您现有的一项android/app/src/main/AndroidManifest.xml
,包含VIEW
行动, 的DEFAULT
and BROWSABLE
类别,并且至少有一个<data>
.
然后只需重建并重新安装您的 APK (react-native run-android
), 就是这样!与您匹配的链接<data>
标签现在将在您的应用程序中打开!
现在只需捕获这个 URLLinking.getInitialURL() https://facebook.github.io/react-native/docs/linking.html#getinitialurl in the componentDidMount()
你的主要 Javascript 类!
清单示例:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.yourapp"
android:versionCode="1"
android:versionName="0.1">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:largeHeap="true"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- HERE: -->
<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:scheme="https" android:host="yoursite.net" />
<data android:scheme="https" android:host="yoursite.com" />
<data android:scheme="https" android:host="yoursite" />
<data android:scheme="customscheme" android:host="yourpath" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)