我有两个 react native 应用程序说应用程序 1 和应用程序 2。现在我需要从应用程序 1 启动应用程序 2 传递简单的文本数据。关于使用 this 的研究来自android文档的链接我可以使用缩进从App 1调用App 2的 Activity ,
但问题是我能否将这些数据传递到 App 2 的 React Native 屏幕。我的 App 2 有一个虚拟 Activity 类来接收来自其他应用程序的缩进,但是如果有一个更简洁的方法而不使用缩进来最受欢迎的是在 React Native 中的应用程序之间传递数据。
最佳答案
您可以通过 intents (Android) 将您的简单文本从 App1 传递到 App2
为此,在 App1
安装这个插件
npm i react-native-send-intent
然后通过以下方式发送您的数据
Option 1 : as implicit intent
var SendIntentAndroid = require('react-native-send-intent');
SendIntentAndroid.sendText({
title: 'Please share this text',
text: 'Lorem ipsum dolor sit amet, per error erant eu, antiopam intellegebat ne sed',
type: SendIntentAndroid.TEXT_PLAIN
});
Option 2 : Specify Your App
// You can specify arbitrary intent extras to be passed to the app
SendIntentAndroid.openApp('com.App2',
{"App2PropData1": "just because", "App2PropData2": "Lorem ipsum dolor sit amet, per error erant eu, antiopam intellegebat ne sed"}).then((wasOpened) => {});
在 App2 中
此数据将在 props
中可用
export default class App extends Component {
render() {
console.log('App props', this.props);
console.log('App2PropData1', this.props.App2PropData1);
console.log('App2PropData2', this.props.App2PropData2);
//...
}
}
关于android - 在 Android 中使用 React Native 将简单数据发送到其他应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49550963/