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.

bug: Share API throws an exception while trying to share a local file

See original GitHub issue

Bug Report

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 2.4.2
  @capacitor/core: 2.4.2
  @capacitor/android: 2.4.2
  @capacitor/electron: 2.4.2
  @capacitor/ios: 2.4.2

Installed Dependencies:

  @capacitor/ios not installed
  @capacitor/core 2.4.1
  @capacitor/cli 2.4.1
  @capacitor/android 2.4.1
  @capacitor/electron not installed

Platform(s)

Android

Current Behavior

When you use the .share method to share a file of the app it throws the following error:

D/Capacitor: App paused E/DatabaseUtils: Writing exception to parcel java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.***.fileprovider/my_cache_images/log/log_2020-10-01_135743.txt from pid=30905, uid=1000 requires the provider be exported, or grantUriPermission() at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:729) at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:602) at android.content.ContentProvider$Transport.query(ContentProvider.java:231) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:104) at android.os.Binder.execTransactInternal(Binder.java:1021) at android.os.Binder.execTransact(Binder.java:994)

Expected Behavior

Not throwing any error while trying to share a file. And being able to attach it to another apps like Gmail, Whatsapp, etc.

Code Reproduction

Having a file saved for example in cache folder using capacitor FileSystem plugin, try to share it using the Share plugin like:

let shareRet = await Share.share({ title: 'share-title', url: "file:///data/user/0/com.***/cache/log/log_2020-10-01_135743.txt", dialogTitle: 'share-dialog-title' });

Other Technical Details

npm --version output: 6.14.8

node --version output: v12.18.3

Additional Context

I am sure that this is because the plugin needs to add Intent.FLAG_GRANT_READ_URI_PERMISSION to the Chooser intent. See this example in stackoverflow: https://stackoverflow.com/a/59439316

I managed to solve it locally using the solution provided in that link and a few others that are pretty much the same. I cannot share it as pull request because I am not using GIT and I don’t have the time at all.

It basically consist in going to the Share.java file and setting the “fileUrl” as local variable variable just before the EXTRA_STREAM is added. Then, after the chooser Intent is created, you “grantUriPermission” to the packages by “queryIntentActivities” in the chooser, just like the example provided in stackoverflow.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
imhoffdcommented, Nov 18, 2020

2.4.3 is out with this fix.

0reactions
ionitron-bot[bot]commented, Nov 11, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - IOException: The process cannot access the file 'file path ...
The error message is pretty clear: you're trying to access a file, and it's not accessible because another process (or even the same...
Read more >
Debugging System.IO.FileNotFoundException - Cause and fix
In all instances this error is caused by trying to access a file that isn't there. ... Boolean useRights, FileShare share, Int32 bufferSize, ......
Read more >
Known issues with Android Studio and Android Gradle Plugin
This error occurs on Linux-based platforms when starting the native debugger. It indicates that one of the libraries required by the native debugger...
Read more >
Error handling and messages for Community Connectors
Error handling and messages for Community Connectors ; Types of errors. Connector internal error; Connector external error; Looker Studio error.
Read more >
Bug descriptions — spotbugs 4.7.3 documentation
This method might drop an exception. In general, exceptions should be handled or reported in some way, or they should be thrown out...
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