anbu selvan
anbu selvan

Reputation: 745

Sending Simple Data to Other Apps using React Native in Android

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.

Upvotes: 4

Views: 3530

Answers (2)

user3360729
user3360729

Reputation: 1

I am unable to receive data through props earlier. But I solved it by adding following code in Mainactivity.java in second app

@Override
    protected ReactActivityDelegate createReactActivityDelegate() {
        return new ReactActivityDelegate(this, getMainComponentName()) {
            @Override
            protected Bundle getLaunchOptions() {
                Intent intent = MainActivity.this.getIntent();
                return intent.getExtras();
            }
        };
    }

and get data via props like

console.log(props.name) 

where you want to receive data in second app. Hope this will help.

Upvotes: 0

Vinayak B
Vinayak B

Reputation: 4510

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);
        //...
    }
}

Upvotes: 2

Related Questions