My Android App downloads some images from the internet using facebook's Fresco library. For displaying these images in a WebView
and sharing them, I use Fresco to retrieve the images and write them to a temporary file in my App's internal cache dir:
final File tempFile = new File(new File(cx.getCacheDir(), "fresco_cache/"), filename);
saveInputStream(tempFile, is, new FileSaverCallback() {
@Override
public void onSuccess() {
Uri localUri = CacheContentProvider.getContentUriFromUrlOrUri(url);
callback.onSuccess(url, localUri.toString());
}
@Override
public void onFailure() {
callback.onFailure(url);
}
});
Then, I have a custom ContentProvider
for providing access to these files. The provider successfully resolves the Uri
, because I use the images internally by their content URI instead of the real file path. However, when I try to share an image using
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(ARG_IMAGE_URI));
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share"));
the sharing doesn't work with most applications, but does work with a few. I can, for instance, attach the file to an email using K-9, but cannot share it with Google Keep (It says: "Error importing data").
My ContentProvider
is registered like this:
<provider
android:name=".helpers.CacheContentProvider"
android:authorities="my.app.files"
android:exported="true"
android:grantUriPermissions="true"/>
I checked, that the openFile()
function is correctly called and returns a valid ParcelFileOpener
:
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
final File f = getFileForUri(getContentUriFromUrlOrUri(uri.toString()));
if (f.exists())
return ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
throw new FileNotFoundException(uri.getPath());
}
How can I debug that issue? What could I do wrong?
Edit: The sharing used to work with the old implementation of my code, where I used Universal Image Loader instead of Fresco. The only difference I see is that now the images are saved to the interal cache, while before they were saved to /sdcard/data/my.app/..
.