I'm trying to share an image from my assets folder. My code is:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpg");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///assets/myImage.jpg"));
startActivity(Intent.createChooser(share, "Share This Image"));
but it doesn't work. Do you have any ideas?
Complementing what @intrepidis answered:
You will need override methods like example class above:
I needed to override two times the query method. And add these lines above tag in your androidmanifest.xml:
And with this, all work like a charm :D
This blog explains it all:
http://nowherenearithaca.blogspot.co.uk/2012/03/too-easy-using-contentprovider-to-send.html
Basically, this goes in the manifest:
The content provider class has this:
And the calling code does this:
AFAIK, there's no way to share an image from the
assets
folder. But it's possible to share resources from theres
folder.It is possible to share files (images including) from the assets folder through a custom
ContentProvider
You need to extend
ContentProvider
, register it in your manifest and implement theopenAssetFile
method. You can then assess the assets viaUri
sMany apps require you to provide name and size of the image. So here is an improved code (using Google's FileProvider code as an example):
To share from assets folder I can only recommend the cwac-provider library (StreamProvider).
Among avoiding to develop your own content provider, it adds some support for capricious legacy apps (check
USE_LEGACY_CURSOR_WRAPPER
).