6

I am using build variants with Firebase and my application also needs to use FileProvider for sharing app files to be opened in 3rd party apps. But when I am trying to send the URI in the intent, the app crashes giving following error.

error:java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/com.example.debug/files/Pictures/JPEG_20170919_113955_102027655.jpg

Heres my configuration String authority = getString(R.string.authority_provider); Uri fileUri = FileProvider.getUriForFile(context, authority, file);

  • Added file provider into AndroidManifest.xml at inside of application tag:

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

  • file_paths.xml

    <?xml version="1.0" encoding="utf-8"?> <paths> <external-path name="my_images" path="Android/data/${applicationId}/files/Pictures" /> <external-file-path name="my_images" path="Android/data/${applicationId}/files/Pictures" /> </paths>

As Firebase mandates using 2 application IDs to keep crash logs, analytics separate in Firebase Console

  • String: authority_provider - added into build.gradle(app):

    buildTypes { release { --- applicationIdSuffix "com.example" resValue "string", "authority_provider", "\"com.example.fileprovider\"" --- } debug { --- applicationIdSuffix '.debug' resValue "string", "authority_provider", "\"com.example.debug.fileprovider\"" --- } }

  • File: and creating file into ExternalFilesDir and saving downloaded data into it and using same file object to get URI.

    File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); File file = File.createTempFile(fileName, fileExtension, storageDir);

I have tryed following solution to solve but not worked for me:

Also followed this blog post.

Sumit Jain
  • 1,100
  • 1
  • 14
  • 27
  • `name="my_images"`. You have that twice. For different paths. Not good. Use different names and use path="." for both. – greenapps Sep 19 '17 at 07:27
  • Thank you its working. But found better and more safe solution. Just need to replace code of **file_paths.xml** with following: **` `** – Sumit Jain Feb 18 '19 at 04:25

0 Answers0