Ashokkumar
Ashokkumar

Reputation: 325

React native app to receive share links from apps like youtube

I am new to React native. I am developing an app to receive shared url like in youtube share which shares the url.like this 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

Answers (4)

Ashokkumar
Ashokkumar

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

warl0ck
warl0ck

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

Maneesh
Maneesh

Reputation: 674

You can use Deep Linking from react-navigation. Check this Article for example.

Upvotes: 5

Vinil Prabhu
Vinil Prabhu

Reputation: 1289

You can do this with react-native-share-extension

Upvotes: 4

Related Questions