Skip to content
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

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

Open
fttx opened this issue Aug 30, 2022 · 2 comments
Open

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

fttx opened this issue Aug 30, 2022 · 2 comments

Comments

@fttx
Copy link

fttx commented Aug 30, 2022

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:

  • minSdkVersion: 19
  • targetSdkVersion: 30
  • cordova-android: 8.1.0
  • cordova-plugin-x-socialsharing: ^6.0.3
@AuTiiTo
Copy link

AuTiiTo commented Sep 28, 2022

I have the same issue.

@raeesaa
Copy link

raeesaa commented Mar 31, 2023

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

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

No branches or pull requests

3 participants