深度链接在 Android 上的 React Native 应用程序中不起作用

Tom*_*Tom 6 android react-native expo android-deep-link expo-linking

我已经将我的 React Native 应用程序设置为将深度链接与 expo-linking 结合使用,但由于某种原因,它无法在 Android 上运行(尚未在 iOS 上实现)。打开链接只会在网络浏览器中打开它,而不会按应有的方式打开应用程序。知道为什么吗?

应用程序.json

"android": {
  "adaptiveIcon": {
    "foregroundImage": "./assets/adaptive-icon.png",
    "backgroundColor": "#FFFFFF"
  },
  "package": "com.example.myapp",
  "intentFilters": [
    {
      "action": "VIEW",
      "data": [
        {
          "scheme": "https",
          "host": "testlink.com",
        }
      ],
      "category": [
        "BROWSABLE",
        "DEFAULT"
      ]
    }
  ]
},
Run Code Online (Sandbox Code Playgroud)

这并没有更新AndroidManifest,所以我手动编辑了它:

AndroidManifest.xml

<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:scheme="https" android:host="testlink.com"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

应用程序.js

const linking = {
    prefixes: ["https://testlink.com"],    
};

useEffect(() => {
    Linking.addEventListener("url", handleDeepLink);

    return () => {
        Linking.removeEventListener("url", handleDeepLink);
    };
}, []);

return (
    <NavigationContainer /*linking={linking}*/>
        ....
    </NavigationContainer>
);
Run Code Online (Sandbox Code Playgroud)

这仅适用于普通的博览会链接,但现在不起作用我想要一个自定义 URL,以便它在计算机上的网络浏览器中打开,或者在安装了应用程序的情况下在应用程序上打开。

Fis*_*uel 4

iOS Safari 浏览器的核心具有内置的深度链接,可以深度链接到自定义应用程序架构 - myapp:///link-to-resources. 主要在 Android 上使用的基于 Chromium 的浏览器不支持URL 输入字段中的自定义应用程序架构。

解决方法是设置一个简单的网页,可以使用浏览器 DOM 窗口 API 重定向您的应用程序自定义架构。

 const launchApp = (deepLink = "", fallBack = "") => {
  var now = new Date().valueOf();
  setTimeout(function () {
    if (new Date().valueOf() - now > 100) return;
    window.location = fallBack;
  }, 25);
  window.location = deepLink;
}


 const deepLink = "myapp:///path_to_ressource/";
 const fallbackLink = "http://play.google.com/store/apps/details?id=com.yourcompany.appname"

launchApp(deepLink,fallbackLink)

Run Code Online (Sandbox Code Playgroud)