Reputation: 325
I am new to React native. I am developing an app to receive shared url like in youtube share which shares the url. I have added the code to register receive activity in xml like this
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
But in my App.js code how could i receive the data and do further processing.
Upvotes: 4
Views: 7070
Reputation: 325
I got the easy way to get the shared text value from other apps as mentioned in the article
This lets us to get the shared text in render props
for the app initially.
Upvotes: 1
Reputation: 3464
So get the initial launched url you can actually use the inbuild react-native functionality of Linking
where in you main/root file you can just listen you initial launch params as
componentDidMount = () => {
Linking.getInitialURL().then((url) => {
// if your app was launched from the share you will get the text
// else url will be null
if (url) {
console.log('shared string/text is ', url);
}
}).catch(err => console.error('An error occurred', err));
}
React native Linking docs link
Upvotes: 4
Reputation: 674
You can use Deep Linking from react-navigation
. Check this Article for example.
Upvotes: 5