Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Share file throws SecurityException #127

Closed
angel-garcia-lopez opened this issue Oct 1, 2020 · 1 comment
Closed

Share file throws SecurityException #127

angel-garcia-lopez opened this issue Oct 1, 2020 · 1 comment

Comments

@angel-garcia-lopez
Copy link

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

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)

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](url)

I am calling the API like this:

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

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.

Regards,

@jcesarmobile
Copy link
Member

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants