首页 > 解决方案 > 是否可以将参数从一个 react-native 应用程序传输到另一个 react-native 应用程序?

问题描述

我试图将参数从一个 react-native 应用程序传递到另一个 react-native 应用程序。我知道这是可能的并且在 Android 中做得很好,但只是想知道如何在 react-native 中完成它。

一个调用者应用程序让我们说 Param_send_App、Param_receive_app。

从 Param_send_App 我会打电话Linking.openURL('param_receive_app://app?param1=test&param2=test2') ,但我将如何在 Param_receive_app 接收参数?

标签: javascriptandroidreact-nativereact-navigation

解决方案


嗯,这真的很容易,当问题发布的那天自己就得到了答案。因为您可以将参数从Param_send_App 传递Param_receive_app

Linking.getInitialURL().then((url) => {
                if (url) {
                    console.log(url);
                }
                else {
                    console.log("No Parameter found, perform any other operation");
                }
            }).catch(err => console.error('Silently capture the error', err));

但是还有一件事要做在 AndroidManifest.xml 中添加

<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="param_receive_app" />
        </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="com.param_receive_app" />
        </intent-filter>

哪里param_receive_app是必需的包名。


推荐阅读