【问题标题】:Clear share intent data while whatsapp sharing in android在android中whatsapp共享时清除共享意图数据
【发布时间】:2016-05-19 09:54:59
【问题描述】:

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


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


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

这是用来创建目录的:

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:"));

【问题讨论】:

    标签: android android-intent bitmap


    【解决方案1】:

    String imageNameForSave 中使用动态名称 前任。 String imageNameForSave = "/qqq" + mydate + ext;

    【讨论】:

      猜你喜欢
      • 2014-09-05
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 2012-05-05
      • 1970-01-01
      • 2022-06-25
      • 2016-10-16
      相关资源
      最近更新 更多