【问题标题】:Open external App from React native App ( Button Click)从 React 本机应用程序打开外部应用程序(按钮单击)
【发布时间】:2018-08-10 09:29:13
【问题描述】:

我想通过点击我使用过的按钮打开新的 React 原生应用

在 React Native 中链接概念

React native Code : Test 是 Other App 的名称

Linking.openURL('Test://app');

还有在 android.manifest.xml 文件中添加 Intent 的 URL Andriod Intent

代码:Android.manifestfile.xml

  <activity
        android:name=".MainActivity"
        android:launchMode="singleTask"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <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="com.Test" />
              <category android:name="android.intent.category.BROWSABLE" />
              <data android:scheme="Test" android:host="app" />
          </intent-filter>
      </activity>

我该如何解决这个问题?

【问题讨论】:

  • 我觉得好就好。实现此代码后您是否进行了构建。
  • 是的,我已经完成了构建,但它给了我错误(在 react native 中找不到处理意图 act​​=android.intent.action.view 的活动)
  • 我希望你有 react-native 应用程序。从A应用你要打开B应用。对在应用程序中使用此代码 Linking.openURL('Test://app');并在 B 应用程序更改代码:Android.manifestfile.xml 文件。对,请清楚..我说得对吗?
  • 我只在 App A 中做这两件事
  • 为什么?你想在自己点击打开相同的应用程序?

标签: javascript android reactjs react-native


【解决方案1】:

将此代码添加到与当前意图过滤器并行的 AndroidManifest.xml 文件中

 <intent-filter android:label="@string/app_name">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Accepts URIs that begin with "example://gizmos” -->
        <data android:scheme="app"
              android:host="testApp" />
    </intent-filter> 

然后运行这个命令React-native run-android

将以下代码添加到您的 react-native 文件中。

<Button title="Click me" onPress={ ()=>{ Linking.openURL('app://testApp')}} />

为了节省时间。您可以在同一个应用程序中同时编写代码,并且同一个应用程序将在按下按钮时打开

我只是试试这段代码,它对我有用 如果仍然面临问题,请告诉我(Y)

【讨论】:

  • 抱歉,Anil 回复晚了。不,它不起作用,我同时应用了上面的代码。当我点击按钮时,它的反映并回到同一个地方。 (就像向右滑动一样,之后打开了相同的活动)......
  • 我已经在 App B androidmanifesfile.xml 中完成了上述代码,其中 android:host 名称将与我的应用程序文件夹名称 (testAppA) 相同,现在从 testAppA 中单击,但它不会重定向到那个 ( testAppB )请帮助点击正在工作,但它不会打开新的反应原生应用程序。
  • 如果我使用这种链接 URL 的方式 (Linking.openURL('testAppA://app')) 它会给我错误,因为不处理查看意图
  • 能否给我看看App B androidmanifesfile.xml的代码和文件的链接代码
  • 代码:文件夹名称 (AppFighter) 我已经在 ChrisApp 清单文件中编写了此代码。 链接打开Chris App (
【解决方案2】:

您可以使用以下代码打开外部应用程序

Linking.canOpenURL("fb://app").then(supported => {
  if (supported) {
    Linking.openURL("fb://app");
  } else {
    alert('sorry invalid url')
  }
});

【讨论】:

  • 它不能与谷歌地图应用程序和其他应用程序一起使用它工作得很好,知道吗?
【解决方案3】:
<Button title="Click me" onPress={ ()=>{ Linking.openURL('https://google.com')}} />

这里是您可以查看的链接:https://snack.expo.io/rJm_YkqyW

【讨论】:

  • 这个链接对浏览器 URL 很有用,我想通过点击按钮打开另一个 App(React Native)
猜你喜欢
  • 2018-03-21
  • 2021-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-26
  • 1970-01-01
  • 2017-02-15
  • 1970-01-01
相关资源
最近更新 更多