0

I try to open pdf file.

AndroidManifest.xml

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.interactivegroup.android.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />

    </provider>

my pdf files in Download folder on the Android device

file_paths.xml

<?xml version="1.0" encoding="utf-8"?><paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="files" path="." />
<root-path name="pdfs" path="/storage/emulated/0/Download" />

open file method

File file = new File(Environment.DIRECTORY_DOWNLOADS+"/Киоски.pdf");

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    Uri uri = FileProvider.getUriForFile(SendActivity.this,  "com.interactivegroup.android.fileprovider", file);
    intent.setDataAndType(uri, "application/pdf");
    SendActivity.this.getApplicationContext().startActivity(intent);

And i always catch this Exception

Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /Download/Киоски.pdf

I cannot find enough explanation what's wrong.

Sorry for my broken English((((

Thanks.

  • Possible duplicate of [FileProvider - IllegalArgumentException: Failed to find configured root](https://stackoverflow.com/questions/42516126/fileprovider-illegalargumentexception-failed-to-find-configured-root) – Ashvin solanki Sep 10 '18 at 15:02

1 Answers1

0

I would change the file_path.xml to:

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

and try:

Uri contentUri = getUriForFile(getContext(), "com.interactivegroup.android.fileprovider", newFile);
Andrea Nagy
  • 1,201
  • 9
  • 21