Sunday, April 8, 2018

Sending Simple Data to Other Apps using React Native in Android

Leave a Comment

I have two react native apps say App 1 and App 2.Now i need to start App 2 from App 1 passing simple text data.On research using this link from android documents i am able to call the activity of App 2 from App 1 using indents,

Sample Image of opening App2 from App1

But the question is will i be able to pass these data to the React Native screen of App 2.My App 2 has a dummy Activity class to receive indents from other apps but if there is a much neat approach without using Indents to pass data between apps in React Native is most welcome.

1 Answers

Answers 1

You can pass your simple text from App1 to App2 via intents (Android )

for this , In App1

install this plugin

npm i react-native-send-intent 

Then send your data as following ways

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) => {}); 

In App2

this data will be available in the 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);         //...     } } 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment