0 votes
in Education by (1.7m points)
I looked at all the answers on StackOverflow and there no answer for me.

Same error for real device and emulators.

Fileprovider always throws IllegalArgumentException

There is Manifest

<application

   ...

    <provider

        android:name="android.support.v4.content.FileProvider"

        android:grantUriPermissions="true"

        android:exported="false"

        android:authorities="${applicationId}">

        <meta-data

            android:name="android.support.FILE_PROVIDER_PATHS"

            android:resource="@xml/filepath"/>

    </provider>

</application>

There is filepath.xml

<paths>

<files-path

    name="logs"

    path="logs/" /></paths>

And there is code which always throw exception

        final Intent emailIntent = new Intent(Intent.ACTION_SEND);

        emailIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

        File file = new File(logger.getFileName());

        Uri uri = null;

        try {

            uri = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID, file);

        } catch (IllegalArgumentException e) {

            e.printStackTrace();

        }

logger.getFileName() - returns real file name for example: "logs_22032019.txt"

What I already tried: Changes in Manifest such as: android:authorities="com.realname.of.package" Changes in filepath.xml

name="logs"

1) same name of file 2) just /

path="logs/"

1) . 2) / 3) full path 4) files 5) /files 6) files/ e.t.g

What I'm noted - there is really the path of files:

/data/user/0/com.app.realname/files/log.txt

But FileProvider in it goes to:

"log.txt" -> "/data/data/com.app.realname/files/log.txt"-->

NOTE: I need only INTERNAL storage.

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
logger.getFileName() - returns real file name for example: "logs_22032019.txt"

That is not a valid filesystem path. It is a valid filename, but it does not say where that file is supposed to be on the device.

This is your FileProvider configuration:

<files-path

    name="logs"

    path="logs/" />

For that, a File that would work is:

File file = new File(getFilesDir(), "logs/"+logger.getFileName());

there is really the path of files... But FileProvider in it goes to

Those are the same filesystem location, for the primary device user.
...