Skip to content Skip to sidebar Skip to footer

Retrieving Content Uri Using File Provider Fails

I have spent days reading the docs and following various tutorials for this but I am getting errors whatever I do. I am trying to save an image in Internal Storage and then convert

Solution 1:

"@string/file_provider_authority" is not how you reference string resources in Java. Use getString(R.string.file_provider_authority).

UPDATE: Based on the comments, the second major problem is that the consumer of this content isn't using the MIME type from the Intent, but instead is calling getType() on a ContentResolver to get the type from the ContentProvider. In this case, that is your FileProvider, and FileProvider only knows how to work with file extensions and converting those to MIME types. So, using temp.jpeg gave FileProvider the information necessary to return the proper MIME type.

Solution 2:

Try This

      Uri imageUri = FileProvider.getUriForFile(MainActivity.this, R.string.file_provider_authority, file);

Also Change

    <paths>
    <files-pathpath="/" name="temp" />

To

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

Post a Comment for "Retrieving Content Uri Using File Provider Fails"