Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Share Image Doesn't Clear the Preview from a previously shared item

Simple question, I have code set up to create a bitmap of an image and share it out via Action_Send. When it's shared, the correct image does send, but the preview of the image that shows up in the message field(if you're sending it via text) shows a previously shared item. Is there any way to force that preview to refresh? Below is an image that shows the field I'm talking about. The preview that's there is not the currently shared image, but a previous one from many shares ago that never cleared.

http://i.stack.imgur.com/dT78Z.png

private Intent getShareIntent() 
{ 
Intent shareIntent = new Intent(Intent.ACTION_SEND); 
File sdCard = Environment.getExternalStorageDirectory(); 
File sharedFile = new File(sdCard+"/SaveDirectory/mypicture.png"); 
Uri uri = Uri.fromFile(sharedFile);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri); return shareIntent; 
}
like image 991
jagrakye Avatar asked May 07 '15 04:05

jagrakye


1 Answers

I saw same issue. This issue only exists for few apps, like google's apps such as keep, g+, etc.

These apps retain the preview if the file is same. Not sure why they made such assumption. In short, the preview is preserved per file and not updated even after the file is changed. We can't fix these apps, so the solution is to avoid updating the same file.

Create a temporary file using File.createTempFile() which ensures that a new unique file is created. This way preview will get updated.

In my case, I created these temporary files in cache dir (getCacheDir() or getExternalCacheDir()) and clear the cache onDestroy().

like image 72
rpattabi Avatar answered Sep 28 '22 13:09

rpattabi