我有图像查看和共享按钮的活动,
从数据库检索的图像
我想先保存图像然后再共享
一切都很顺利,图像保存在内存中,并将共享,但当其他应用程序运行时(如whatsapp或消息),它说文件不支持
我已手动将其他图像推送到DDMS,然后共享是没有任何问题的工作!哦!
我想问题出在保存位图上,即使我从DDMS中检查了保存的位图,它看起来也不错
这是我的密码:
节约

  try {
        FileOutputStream out = new FileOutputStream(new File(getFilesDir(), "temp.png"));
        imageview.setImageBitmap(b1);
        b1.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
       }
       catch (Exception e) {}

分享法
  private void initShareIntent(String type,String _text)
  {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(getFilesDir(), "temp.png")));
        shareIntent.setType("image/PNG");
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(Intent.createChooser(shareIntent, "send"));
  }

最佳答案

编辑此

shareIntent.setType("image/*");

对此
shareIntent.setType("image/png");

我觉得应该管用。如果对你有用就告诉我!!
[edit1]改为png(而不是png),因为我认为这里的情况很重要。大声笑
[edit2]对于多个图像,请尝试此操作(由google:p提供)
ArrayList<Uri> imageUris = new ArrayList<Uri>();
imageUris.add(imageUri1); // Add your image URIs here
imageUris.add(imageUri2);

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));

10-07 19:47
查看更多