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?
Step 3 – Right click app >> New >> Folder >> Assets folder. Right click on the assets folder, select New >> file (myText. txt) and your text.
Assets provide a way to include arbitrary files like text, xml, fonts, music, and video in your application. If you try to include these files as "resources", Android will process them into its resource system and you will not be able to get the raw data.
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 the openAssetFile
method. You can then assess the assets via Uri
s
@Override public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException { AssetManager am = getContext().getAssets(); String file_name = uri.getLastPathSegment(); if(file_name == null) throw new FileNotFoundException(); AssetFileDescriptor afd = null; try { afd = am.openFd(file_name); } catch (IOException e) { e.printStackTrace(); } return afd; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With