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.

[Android] Sharing data uri silently fails without WRITE_EXTERNAL_STORAGE

See original GitHub issue

Tried with RN 0.44, Android M & N.

I cannot get the url option to work to share an image. I’m using a data URI of an image. I’ve also tried the sample code in this repo.

  • If I do Share.open and pick:
    • Gmail url is ignored. (subject and message work)
    • “Upload to Photos” I get a toast saying “Error, could not load media”
    • “Save to Drive” I get a toast saying “Upload was unsuccessful, request contained no data”

It seems like the url is dropped on the way. I’m going to see if I can step through the code in Android Studio to make sure the URL gets all the way to the intent.

(FWIW, this works great in iOS)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
RUIFERNANDE5commented, May 15, 2017

Thank you for sharing, tough I solved this by setting permissiosAndroid and writing the file I wanted on a external directory since its the only accepted path on all android apps.

0reactions
Michael-Benecaidcommented, Mar 1, 2018

How to write the file on an external directory? I am using react-native-fetch-blob to write the file,

addAndroidDownloads : {
            useDownloadManager : true, // <-- this is the only thing required
            // Optional, override notification setting (default to true)
            notification : true,
            // Optional, but recommended since android DownloadManager will fail when
            // the url does not contains a file extension, by default the mime type will be text/plain
            title:`xxx.pdf`,
            mime : 'application/pdf',
            description : 'File downloaded by download manager.',
            mediaScannable : true,
            path: RNFetchBlob.fs.dirs.DownloadDir+`xxx.pdf`           
          }

and share the pdf as

Share.share({
      title: 'xxx',
      url: `${path}`
      }
    )

Gmail still ingnore the url, can anyone help this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Android] Sharing data uri silently fails without ... - GitHub
Tried with RN 0.44, Android M & N. I cannot get the url option to work to share an image. I'm using a...
Read more >
android - Share image without WRITE_EXTERNAL_STORAGE?
The share works fine when the uri points to a file in getExternalFilesDir() , but I'd prefer a solution that does not require...
Read more >
Manifest.permission - Android Developers
Old permission for deleting an app's cache files, no longer used, but signals for us to quietly ignore calls instead of throwing an...
Read more >
Data and file storage overview - Android Developers
Shared storage: Store files that your app intends to share with other apps, including media, documents, and other files. Preferences: Store private ...
Read more >
Storage updates in Android 11 - Android Developers
If your app targets Android 11, both the WRITE_EXTERNAL_STORAGE permission and the WRITE_MEDIA_STORAGE privileged permission no longer provide any additional ...
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