Listening for incoming links on Android with React-Native

前端 未结 1 1560
迷失自我
迷失自我 2021-02-11 02:07

I am able to listen and handle incoming links on IOS with react-native using the linking library: https://facebook.github.io/react-native/docs/linking.html, but it shows the fun

相关标签:
1条回答
  • 2021-02-11 02:40

    I just got it working! You just have to follow these instructions.

    Basically, add an <intent-filter> under the existing one of your android/app/src/main/AndroidManifest.xml, containing the VIEW action, the DEFAULT and BROWSABLE categories, and at least a <data>.

    Then simply rebuild and reinstall your APK (react-native run-android), that's it! Links matching your <data> tags will now open in your app!

    Now just catch this URL with Linking.getInitialURL() in the componentDidMount() of your main Javascript class!

    Example of manifest:

    <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>
    
    0 讨论(0)
提交回复
热议问题