清除共享意图数据,同时whatsapp在android中共享



我有一个相对布局和Textview。然后我将相对布局转换为位图图像并保存在目录中。


问题是,当我共享图像时,在大多数应用程序中,我都找到了正确的图像,但在whatsapp的情况下,当我通过whatsapp共享时,共享图像的预览会显示我旧的图像,直到我关闭应用程序。为什么它没有得到更新,当我在whatsapp上分享图像时,预览是旧的,图像是正确的。这在FB、Gmail等中运行良好…


这是以下代码,用于在文件系统(目录)中转换和保存转换后的位图图像

这是用于创建Direcory:

File dir = null;
String directorySubPath = "Android/data/com.domainname.appname/sharedResource/";
String imageNameForSave = "/qqq.png";
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
        {
            Toast.makeText(this, "Your device doesn't have external storage.", Toast.LENGTH_SHORT).show();
            return;
        }
        else
        {
            Log.d("SD", "YES", null);
            dir = new File(Environment.getExternalStorageDirectory()+File.separator+directorySubPath);
            if (!dir.exists()){
                dir.mkdirs();
            }
            else {
                Log.d("Q-Design:", "Already created", null);
            }
        }

这是用于将布局转换为位图图像的代码&保存

rLayout.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(rLayout.getDrawingCache());
FileOutputStream out = new FileOutputStream(dir+imageNameForSave);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
rLayout.setDrawingCacheEnabled(false);

这是为了通过Intent共享图像:

Uri uri = Uri.parse("file:///" + dir + imageNameForSave);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test Mail");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Data Shared with you..."); 
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share via:"));

String imageNameForSave中使用动态名称例如字符串imageNameForSave="/qqq"+mydate+ext;

最新更新