2

After hours of searching and testing, I cannot get my head through this challenge.

I am trying to share data (url, image) from another app --> to my app.

But I was not able to find proper documentation on how to achieve this (on Android and iOS), or reliable modules ( react-native-share-extension seems an overkill and does not work with react-native-navigation v2 (#139) and react-native-share-menu is not maintained for iOS)

Let's talk a bit about Android, I did update my manifest <intent-filter> with (btw, what is the equivalent in iOS?)

    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
        <data android:mimeType="text/plain" />
    </intent-filter>

and successfully see my app on other app's share to list... and clicking on it opens my app ... check

Now I need to actually GET the intent data in my app. I tried using Linking from react-native, without any success, I get none of the console logs.

Below is my code, what am I missing, or should i do for my Android and iOS projects, to get the intent data?

index.js

import App from './App';

App.js

import { persistStore } from 'redux-persist';
import { Navigation } from "react-native-navigation";
import { Linking } from 'react-native';
// other imports ...
// [...]

const handleOpenURL = (event) => {
  console.log(event.url);
};

Linking.addEventListener('url', handleOpenURL);
Linking.getInitialURL().then((url) => {
    if (url) {
      console.log('Initial url is: ' + url);
    }
  }).catch(err => console.error('An error occurred', err));

Navigation.events().registerAppLaunchedListener(() => {
   persistStore(store, null, () => {
    // Register Screens ...
    Navigation.setRoot({
    // Setting root to home page (home.js)

Home.js // also tried there

// imports
class Home extends Component {
//...
   _handleOpenURL(event) {
    console.log(event.url);
   };
   componentDidMount() {
      Linking.addEventListener('url', this._handleOpenURL);
      Linking.getInitialURL().then((url) => {
        if (url) {
            console.log('Initial url is: ' + url);
        }
      }).catch(err => console.error('An error occurred', err));
   }

MainActivity.java // this is probably where I am missing something like getIntent() ?

package com.my.app;

import com.imagepicker.permissions.OnImagePickerPermissionsCallback;
import com.facebook.react.modules.core.PermissionListener;
import com.reactnativenavigation.NavigationActivity;

public class MainActivity extends NavigationActivity implements OnImagePickerPermissionsCallback {

  private PermissionListener listener;

  @Override
  public void setPermissionListener(PermissionListener listener) {
    this.listener = listener;
  }

  @Override
  public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (listener != null) {
      listener.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  }

}

I tried on the above MainActivity the solution from Dave Bennet, but got an error I was not able to solve (error: method does not override or implement a method from a supertype)

Thanks for your help!

------ packages

  • "react": "16.6.3",
  • "react-native": "0.57.8",
  • "react-native-navigation": "^2.6.0"
Andrew
  • 26,706
  • 9
  • 85
  • 101
Jojo
  • 133
  • 3
  • 9

0 Answers0