I am trying to share image file in cache directory, i have the complete path, but not able to send the file in attachments, the code is
File shareImage=Utils.getBitmapFile();
Log.d("Activity", "get final path in result"+shareImage.getAbsolutePath());
/*MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext=shareImage.getName().substring(shareImage.getName().lastIndexOf(".")+1);
String type = mime.getMimeTypeFromExtension(ext);
shareIntent.setType(type);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
Uri shareImageUri = Uri.fromFile(shareImage);
Uri shareImageUri = Uri.fromParts("content", shareImage.getAbsolutePath(), null);//("content://"+shareImage.getAbsolutePath());
*/
Uri shareImageUri = Uri.fromFile(shareImage);
Log.d("Result ","uri is "+shareImageUri.toString());
shareIntent.putExtra(Intent.EXTRA_STREAM, shareImageUri);
startActivity(Intent.createChooser(shareIntent, "Share Results"));
the above commented code is not working
the send mail shows attachment,but not receiving end there is not attachment, facebook sharing also shows no image in post
what the reason for this??
I have already seen the following SO Links how-to-use-share-image-using-sharing-intent-to-share-images-in-android and many others, none of them are able to resolve the issue
P.S.;
1.The aim is to take screenshot of screen save it in cache directory and share it online from there
2.Yes i do have file, I can pull it via DDMS from device and see on system.
As noted, other apps do not have access to your app's internal storage.
Feel free to open a fresh StackOverflow question, where you explain, completely and precisely what specific solutions you have tried and what specific problems you have encountered.
Feel free to open a fresh StackOverflow question, where you explain, completely and precisely what "that does not seems to be working" means.
Or, use
FileProvider
, which offers this capability with no code required beyond an entry for it in your manifest.Or, store your image on external storage, such as
getExternalCacheDir()
.I followed @CommonsWare's advice and used a FileProvider. Assuming your image is already in the internal cache directory as
cache/images/image.png
, then you can use the following steps. These are mostly a consolidation of the documentation.Set up the FileProvider in the Manifest
Replace
com.example.myapp
with your app package name.Create res/xml/filepaths.xml
This tells the FileProvider where to get the files to share (using the cache directory in this case).
Share the image
Documentation
I share cached image by followed steps .
1.Copy your cached image to target path.
2.Get the Uri of copy file.
3.Share image by intent