javascript - 从 React 本机应用程序打开外部应用程序(按钮单击)
问题描述
我想通过单击我使用过的 Button 打开 New React native App
在 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>
我该如何解决这个问题?
解决方案
将此代码添加到与当前意图过滤器并行的 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)
推荐阅读
- javascript - OnClick 不适用于按钮和另一个问题
- asp.net-core - asp.net 核心身份迁移不在生产服务器上执行
- ruby-on-rails - nginx 神秘地停止服务请求
- python - 在 Python/RobotFramework 中将 @ 和 $ 用于动态元素/变量的位置。示例 @{cookies} 和 ${cookies}
- xamarin - 具有多项选择的 Xamarin 表单集合 - 限制所选项目的数量
- ruby-on-rails - 如何使用 rails Test::Unit 或 minitest 只运行一个测试断言?
- python - Scrapy splash 无法登录,lua 错误:尝试调用方法 'send_text'(一个 nil 值)
- python - 每次用户要加密一个新文件时,我是否应该生成一个新的 RSA 密钥对?
- java - 使用java swing调用另一个类的方法来绘制当前类
- android - 当每个项目中有一个字段被内容更新时,设置更新过程的最佳方法是什么