1

I need to share pdf files from my assets folder. The pdf file changes based on language.

Assets structure is like -

  assets
      folder
         countryA
                   languageA
                             pdfA
                   languageB
                             pdfB
         countryB
                   languageA
                             pdfA
                   languageC
                             pdfC

My Android manifest file -

 <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>

When the following code runs

FileProvider.getUriForFile(getActivity(),
    BuildConfig.APPLICATION_ID + ".provider",
    new File("String file name"));

I am getting a java.lang.IllegalArgumentException: Failed to find configured root that contains /file:/android_asset/folder/countryA/languageA/file.pdf

I believe it is because the path in the provider xml is not configured.

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <files-path name="my_file_name" path="."/>
</paths>

I have used files-path as the files are under assets folder. Since the files are nested how do i configure the provider path.

I have consulted the following links

Link1

Link2

Link3

D-D
  • 954
  • 2
  • 12
  • 27
  • `FileProvider` doesn't support assets, out of the box. You could [roll your own `ContentProvider` that does](https://stackoverflow.com/q/5888718), use an existing solution – like CommonsWare's [`StreamProvider`](https://github.com/commonsguy/cwac-provider) – or copy the files out of assets to storage before using `FileProvider`. – Mike M. Jul 26 '18 at 04:56
  • 1
    Thanks a lot. Content providers worked for this use case. Sharing worked using Bluetooth, mail but fails in case of Gmail app. I am working on that. Will share the solution once done. – D-D Jul 30 '18 at 06:29

0 Answers0