react-native-receive-sharing-intent icon indicating copy to clipboard operation
react-native-receive-sharing-intent copied to clipboard

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

Open climsaroj opened this issue 2 years ago • 3 comments

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.

climsaroj avatar Feb 08 '23 11:02 climsaroj

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

Gobinda74 avatar Apr 07 '23 14:04 Gobinda74

remove it ReceiveSharingIntent.clearReceivedFiles();

MiteshKalal7 avatar Apr 17 '23 11:04 MiteshKalal7

remove it ReceiveSharingIntent.clearReceivedFiles();

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

omrip2 avatar Jul 29 '24 05:07 omrip2