-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: Share API throws an exception while trying to share a local file #3638
Comments
The plugin uses a FileProvider that grants access to urls as long as the
Since you say you are writing and sharing from caches folder that should be enough, can you provide a sample project? |
I've never done it before and took me some time but here you are... checkout the repo I just created: |
#3643 I did a pull request according to the suggested changes. |
What's the Android version of the device where you tried and failed? |
Android 10.
Given the android docs I don't think it works in all smartphones or
versions, because they say you need to grant permissions.
El mar., 6 oct. 2020 14:02, jcesarmobile <[email protected]>
escribió:
… What's the Android version of the device where you tried and failed?
I've tested your sample app on Android 8.1 and Android 9 devices and share
worked.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3638 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJYPUSNK2AR3H7EITGPG463SJMBLZANCNFSM4SBUB7MQ>
.
|
I have a similar "Permission Denial" issue on the emulator with Android 10. |
I've been able to reproduce the error message on Android 10 devices. The error don't prevent Share from working, but I've sent a PR that prevents the error from appearing. #3655 As I said, the file provider already grants the read permission to the content URIs by default, not sure why it happens on Android 10, but the problem is on the Chooser intent that wraps the send intent, probably when tries to preview the attachment (since it's an Android 10+ feature). Using the send intent without the chooser don't present the error, but loses some functionality like copying the file or direct share. The PR is simpler than the other proposed changes, and also the other proposed changes are incomplete, if the URI permission is granted that way, it has to be revoked after the share is done and that wasn't implemented. So would be good if you could try my changes and verify if it works for you. |
I tried your changes from #3655 and it doesn't show the error message now.
The sharing itself is also working, so from my point of view this is all
right now.
Thank you.
El jue., 8 oct. 2020 13:09, jcesarmobile <[email protected]>
escribió:
… I've been able to reproduce the error message on Android 10 devices. The
error don't prevent Share from working, but I've sent a PR that prevents
the error from appearing. #3655
<#3655>
As I said, the file provider already grants the read permission to the
content URIs by default, not sure why it happens on Android 10, but the
problem is on the Chooser intent that wraps the send intent, probably when
tries to preview the attachment (since it's an Android 10+ feature). Using
the send intent without the chooser don't present the error, but loses some
functionality like copying the file or direct share.
The PR is simpler than the other proposed changes, and also the other
proposed changes are incomplete, if the URI permission is granted that way,
it has to be revoked after the share is done and that wasn't implemented.
So would be good if you could try my changes and verify if it works for you.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3638 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJYPUSLV4EPLEVS2MQKUP6TSJWMWRANCNFSM4SBUB7MQ>
.
|
closing since I merged #3655 |
2.4.3 is out with this fix. |
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. |
Bug Report
Capacitor Version
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.8node --version
output: v12.18.3Additional 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.
The text was updated successfully, but these errors were encountered: