question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Share.shareSingle() on Android gives back an unknown error

See original GitHub issue

Steps to reproduce

  1. I am using
const shareOptions = {
      url: picture.uri,
      social: Share.Social.INSTAGRAM,
};
Share.shareSingle(shareOptions).then(() => console.log('SUCCESS')).catch(err => console.log('ERROR: ', err));
  1. The Instagram app seems to start to open, but while it is opened the screen is blank and I have back an error: “An unknown error occured”

Expected behaviour

It has to open the Instagram app as it happens in the iOS app.

Actual behaviour

It seems that Instagram app will open, but the screen stays blank and I have a toast back with “An unknown error occured”

Environment

  • React Native version: 0.55.4
  • React Native platform + platform version: Android 7.1.2

react-native-share

Version: npm version

If you need more infos please tell me.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
ddereszewskicommented, Sep 12, 2018

I managed to fix this problem locally, works good for images and photos. What I did is to follow Offical Instagram instruction and check what the lib does different https://www.instagram.com/developer/mobile-sharing/android-intents/

In summary the changes are: provide file path instead of blob, update SingleShareIntent.java file.

It will be good to have someone from maintainer to explain lack of super.open(options); in current implementation if the app is installed

  1. First change to provide the URL instead of the blog in URL, but I guess this should also work with blob. Some example below. It’s important to have the file extension in the saved file, that’s why I used appendExt from RNFetch Blob
const mediaData = await RNFetchBlob.config({ fileCache : true, appendExt : fileExt }).fetch('GET', downloadUrl);
                let url = 'file://'+ mediaData.path();

                const shareOptions = {
                    url
                };
           
               await Share.shareSingle(
                        Object.assign(shareOptions, {
                            social: Share.Social.INSTAGRAM
                        })
                    );
  1. If you are using RNFetchBlob switch to rn-fetch-blobm which is maitained. I also changed filepaths.xml to
<files-path name="my_files" path=""/>
  1. Update SingleShareIntent.java
public void open(ReadableMap options) throws ActivityNotFoundException {
        System.out.println(getPackage());
        //  check if package is installed
        if(getPackage() != null || getDefaultWebLink() != null || getPlayStoreLink() != null) {
            if(this.isPackageInstalled(getPackage(), reactContext)) {
                System.out.println("INSTALLED");
                this.getIntent().setPackage(getPackage());
                super.open(options);  // <--- #### THIS I ADDED  ########
            } else {
                System.out.println("NOT INSTALLED");
                String url = "";
                if(getDefaultWebLink() != null) {
                    url = getDefaultWebLink()
                            .replace("{url}",       this.urlEncode( options.getString("url") ) )
                            .replace("{message}",   this.urlEncode( options.getString("message") ));
                } else if(getPlayStoreLink() != null) {
                    url = getPlayStoreLink();
                } else {
                    //  TODO
                }
                //  open web intent
                this.setIntent(new Intent(new Intent("android.intent.action.VIEW", Uri.parse(url))));
            }
        }
        //  configure default
        super.open(options);
    }
3reactions
IronTonycommented, Aug 20, 2018

Yes, after the first unknown error I got. Maybe I can try to create a RN app basic (using create-react-native-app) and try the package. Tomorrow I will be back with some more info about that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Share.shareSingle() on Android gives back an ... - GitHub
The Instagram app seems to start to open, but while it is opened the screen is blank and I have back an error:...
Read more >
Share.shareSingle | React Native Share - GitHub Pages
This shared message may contain text, one or more files, or both. Open the share dialog with the specific application. This returns a...
Read more >
Android: React-native-share returning "error - Stack Overflow
The error is being caught at Share.open ('Sharing Error'). If anyone could give me some insight as to what I am doing wrong,...
Read more >
how to install express in console Code Example
What is express.js? ... Express.js. ... Write the command to install the express module using global installation. ... What is Express.js ? npm...
Read more >
"Android System isn't responding" error while trying to share ...
While trying to share any file (say photo, pdf or anything), the system is going blank and not displaying the screen with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found