EddyVerbruggen / SocialSharing-PhoneGap-Plugin

👨‍❤️‍💋‍👨 Cordova plugin to share text, a file (image/PDF/..), or a URL (or all three) via the native sharing widget
MIT License
1.78k stars 910 forks source link

Sharing base64 encoded text/csv files fails on newer Android versions #1188

Open fttx opened 2 years ago

fttx commented 2 years ago

I'm using the share method to share CSV files:

this.socialSharing.share(null, this.scanSession.name, "data:text/csv;base64," + base64CSV, null);

It works fine on Android 8.1.0.

On Android 11 I get this error:

2022-08-30 10:41:55.890 16148-16169/com.barcodetopc E/DatabaseUtils: Writing exception to parcel
    java.lang.SecurityException: Permission Denial: reading nl.xservices.plugins.FileProvider uri content://com.barcodetopc.sharing.provider/root/storage/emulated/0/Android/data/com.barcodetopc/files/socialsharing-downloads/Scan_session_1.csv from pid=26069, uid=1000 requires the provider be exported, or grantUriPermission()
        at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:843)
        at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:684)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
        at android.os.Binder.execTransactInternal(Binder.java:1154)
        at android.os.Binder.execTransact(Binder.java:1123)
2022-08-30 10:41:55.911 16148-16169/com.barcodetopc E/DatabaseUtils: Writing exception to parcel
    java.lang.SecurityException: Permission Denial: reading nl.xservices.plugins.FileProvider uri content://com.barcodetopc.sharing.provider/root/storage/emulated/0/Android/data/com.barcodetopc/files/socialsharing-downloads/Scan_session_1.csv from pid=26069, uid=1000 requires the provider be exported, or grantUriPermission()
        at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:843)
        at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:684)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
        at android.os.Binder.execTransactInternal(Binder.java:1154)
        at android.os.Binder.execTransact(Binder.java:1123)
2022-08-30 10:41:55.995 16148-16169/com.barcodetopc E/DatabaseUtils: Writing exception to parcel
    java.lang.SecurityException: Permission Denial: reading nl.xservices.plugins.FileProvider uri content://com.barcodetopc.sharing.provider/root/storage/emulated/0/Android/data/com.barcodetopc/files/socialsharing-downloads/Scan_session_1.csv from pid=26069, uid=1000 requires the provider be exported, or grantUriPermission()
        at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:843)
        at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:684)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
        at android.os.Binder.execTransactInternal(Binder.java:1154)
        at android.os.Binder.execTransact(Binder.java:1123)

And after that, the receiver application will present a toast with a file not found error, or file not support error.

Adding this to the SocialSharing.java file fixes the error, but still, the receiver applications fail to read the file and present the toast error:

                //Context context = cordova.getActivity().getApplicationContext();
                Context context = webView.getContext();
                List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(chooseIntent, PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : resInfoList) {                 
                  String packageName = resolveInfo.activityInfo.packageName;
                  context.grantUriPermission(packageName, finalFileUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }

This is my configuration:

AuTiiTo commented 2 years ago

I have the same issue.

raeesaa commented 1 year ago

@fttx / @AuTiiTo Did anyone of you found the solution for this?