使用action_send_multiple android从url共享多个图像

时间:2016-04-28 08:28:16

标签: android share

我希望从列表网址链接分享相册图片。 这是我的代码:

 public void shareImg(ArrayList<String> arrUrl, String name) {


    ArrayList<Uri> imageUris = new ArrayList<Uri>();
    for(String path : arrUrl /* List of the files you want to send */) {
        File file = new File(path);
        Uri uri = Uri.fromFile(file);
        imageUris.add(uri);
    }
    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.."));

}

但它没有运行,这里发生了什么。请帮我。谢谢每一个人。

1 个答案:

答案 0 :(得分:1)

试试这段代码。 在这里,我将图像从位图解析为URI,并将它们分享为共享意图

private void shareImages() {
ArrayList<Uri> uris = new ArrayList<>();
Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
share.setType("image/jpeg");

ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "title");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");

for(int i = 0; i < bitmaps.size(); i++) {
  Uri uri = activity.getContentResolver().
      insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
      values);

  OutputStream outstream;
  try {
    outstream = activity.getContentResolver().openOutputStream(uri);
    bitmaps.get(i).compress(Bitmap.CompressFormat.JPEG, 100, outstream);
    outstream.close();
  } catch (Exception e) {
    System.err.println(e.toString());
  }

  uris.add(uri);
}

show.set(false);

share.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
activity.startActivity(Intent.createChooser(share, "Share Image"));

}

希望有所帮助:)