如何在不保存的情况下从Internet共享图像?

时间:2014-06-05 21:04:53

标签: android android-intent share

我正在尝试使用共享意图从互联网上分享图像。这不起作用,因为我认为首先需要下载图像:

intent.putExtra(Intent.EXTRA_STREAM, imageUri);

所以我正在下载图片然后分享它:

@Background
protected void tryToShareImage(Intent intent) {
    try {
        URL url = new URL(mImageUrl);
        Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        intent.putExtra(Intent.EXTRA_STREAM, getImageUri(mActivity, image));
    } catch (Exception e) {
        e.printStackTrace();
    }
    startActivity(Intent.createChooser(intent, "Share using..."));
}

public Uri getImageUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}

然而,有一个问题:在我不再需要它之后,图像会停留在图库中。

问题:有没有办法从互联网上共享图像而不先保存?

0 个答案:

没有答案
相关问题