1

Some code that used to work... is no longer working. I can't tell what's wrong now with the new Android updates.

This is the function where I would pass in an array of Uris for some CSV files and then it would launch a chooser to pass them along to wherever the user chooses:

public static void sendCsvFilesToAnotherApp(final AppCompatActivity activity, final ArrayList<Uri> csvUris) {
    Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    String[] mimetypes = {"text/csv", "text/comma-separated-values", "application/csv"};
    sendIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
    sendIntent.setType("text/comma-separated-values");
    sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, csvUris);
    activity.startActivity(Intent.createChooser(sendIntent, "Export CSV file(s)"));
}

And here is the error I get, on the last line activity.startActivity(...:

04-18 15:25:00.172 5475-5475/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.devname.appname, PID: 5475
android.os.FileUriExposedException: file:///storage/emulated/0/Documents/AppNameCSVs/somefile.csv exposed beyond app through ClipData.Item.getUri()
    at android.os.StrictMode.onFileUriExposed(StrictMode.java:1960)
    at android.net.Uri.checkFileUriExposed(Uri.java:2348)
    at android.content.ClipData.prepareToLeaveProcess(ClipData.java:942)
    ...

I have no idea what this means or how to fix it, based on my searching.

EDIT: I've already seen the answer here https://stackoverflow.com/a/38858040/9665241 and as it turns out I've already implemented that solution to deal with a past issue. In other words I have:

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths" />
    </provider>

in my Manifest. And I also have

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>

in res/xml/provider_paths.xml.

0 Answers0