ajith-ab / react-native-receive-sharing-intent

A React Native plugin that enables React Native apps to receive sharing photos, videos, text, urls or any other file types from another app
MIT License
297 stars 106 forks source link

Share file to application worked for the first time then I have to re-load application. #168

Open climsaroj opened 1 year ago

climsaroj commented 1 year ago

My qpplication works perfectly for the first time but then the second time, It's just don't work at all. I have to re-load application and then this function will continued work for file that I shared from the second time.

Here is my code:

  getData = () => {
    var result;
    ReceiveSharingIntent.getReceivedFiles((data) => {
        console.log("InreceivedFile");
        console.log(data);
        var path = "file://" + data[0].filePath;
        if (Platform.OS === "android") {
          result = {
            uri: data[0].contentUri,
            type: data[0].mimeType,
            name: data[0].fileName,
            fileCopyUri: path,
          };
        } else {
          var mimeTrans;
          if (data[0].mimeType === ".pdf") {
            mimeTrans = "application/pdf";
          } else if (data[0].mimeType === ".xml") {
            mimeTrans = "text/xml";
          } else if (data[0].mimeType === ".json") {
            mimeTrans = "application/json";
          }
          result = {
            uri: data[0].filePath,
            type: mimeTrans,
            name: data[0].fileName,
            fileCopyUri: data[0].filePath,
          };
        }
        this.uploadVerify(result);
      },
      (err) => {
        console.log(err);
      },
      "ShareMedia"
    );
  };
componentDidMount() {
    SplashScreen.hide();
    this.getData();
}
componentDidFocus = () => {
    this.getData();
}
componentWillUnmount() {
    ReceiveSharingIntent.clearReceivedFiles();
  }

I've used class based which is not the same as the example. If anyone has encountered this problem, please help.

Thanks.

Gobinda74 commented 1 year ago

My qpplication works perfectly for the first time but then the second time, It's just don't work at all. I have to re-load application and then this function will continued work for file that I shared from the second time.

Here is my code:

  getData = () => {
    var result;
    ReceiveSharingIntent.getReceivedFiles((data) => {
        console.log("InreceivedFile");
        console.log(data);
        var path = "file://" + data[0].filePath;
        if (Platform.OS === "android") {
          result = {
            uri: data[0].contentUri,
            type: data[0].mimeType,
            name: data[0].fileName,
            fileCopyUri: path,
          };
        } else {
          var mimeTrans;
          if (data[0].mimeType === ".pdf") {
            mimeTrans = "application/pdf";
          } else if (data[0].mimeType === ".xml") {
            mimeTrans = "text/xml";
          } else if (data[0].mimeType === ".json") {
            mimeTrans = "application/json";
          }
          result = {
            uri: data[0].filePath,
            type: mimeTrans,
            name: data[0].fileName,
            fileCopyUri: data[0].filePath,
          };
        }
        this.uploadVerify(result);
      },
      (err) => {
        console.log(err);
      },
      "ShareMedia"
    );
  };
componentDidMount() {
    SplashScreen.hide();
    this.getData();
}
componentDidFocus = () => {
    this.getData();
}
componentWillUnmount() {
    ReceiveSharingIntent.clearReceivedFiles();
  }

I've used class based which is not the same as the example. If anyone has encountered this problem, please help.

Thanks.

I had a same issue with receiving intent properly something like this. After a long research, I cheated something to solve it. I know this is not a best solution to your problem but I disabled the back button in the app and it looks fine now.

ReceiveSharingIntent.getReceivedFiles( (fileList) => { ................................ ................................ const backHandler = BackHandler.addEventListener('hardwareBackPress', () => true) return () => backHandler.remove(); <========= adding this (error) => { console.log('error', error); }); }

MiteshKalal7 commented 1 year ago

remove it ReceiveSharingIntent.clearReceivedFiles();

omrip2 commented 1 month ago

remove it ReceiveSharingIntent.clearReceivedFiles();

I had the same issue and it solved my problem, @MiteshKalal7 Thank you very much