首页 > 解决方案 > 在反应移动应用程序上设置应用程序链接

问题描述

我实际上正在制作一个移动应用程序,我会设置链接以在您单击它时打开它。我试图设置应用程序链接,但我似乎没有工作......这是我的代码:

清单.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.didierurban.testLenny">
    ...
  <activity
    android:name="MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
    ...
      <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="example.net" />
      </intent-filter>
    </activity>
  </application>
</manifest>

我的assetlink.json(在https://example.net/.well-known/assetlinks.json上)

// 20210407190840
// https://lenny-girardot.fr/.well-known/assetlinks.json

[
  {
    "relation": [
      "delegate_permission/common.handle_all_urls"
    ],
    "target": {
      "namespace": "android_app",
      "package_name": "com.didierurban.testLenny",
      "sha256_cert_fingerprints": [
        "D4:DC:31:60:E9:B2:3F:2B:DF:23:33:31:49:D3:10:9F:3C:3A:6F:E6:1D:41:6E:DB:17:A3:3E:DD:1C:9C:6A:46"
      ]
    }
  }
]

应用程序.json

{
  "expo": {
    "scheme": "...",
    "name": "...",
    "slug": "...",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "..."
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFF"
      },
      "package": "..."
    },
    "web": {
      "favicon": "./assets/favicon.png"
    }
  }
}

如果应用程序链接无法与 React 一起使用,我可以设置什么使其正常工作?我也尝试使用https://www.npmjs.com/package/node-deeplink但它似乎已经过时了。

谢谢

标签: androidreactjsreact-nativeapplinksandroid-app-links

解决方案


在博览会上,您首先需要schemeapp.json. 例如myawesomeapp

您的清单文件也应该具有与此相同的方案

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.didierurban.testLenny">
    ...
  <activity
    android:name="MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
    ...
      <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="myawesomeapp" />
      </intent-filter>
    </activity>
  </application>
</manifest>

在 ios 上,将其添加到info.plist此处

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>myawesomeapp</string>
            </array>
        </dict>
    </array>

然后,您可以使用 url 打开指向您的应用程序的链接myawesomeapp://

您还可以签出此以从您的 react 本机应用程序链接到其他应用程序

有关博览会中深度链接的更多信息,请在此处查看文档


推荐阅读