与URL android共享意图共享图像

我需要知道是否有可能共享一个图像只使用其共享意图的url。 这是我的代码。

Intent imageIntent = new Intent(Intent.ACTION_SEND); Uri imageUri = Uri.parse("http://img.androidcookie.com/android/face-03.jpg"); imageIntent.setType("image/*"); imageIntent.putExtra(Intent.EXTRA_STREAM, imageUri); startActivity(imageIntent); 

到目前为止,它不工作,我还没有find任何有用的答案在线。 我想这样做,使用共享意图,而不下载图像。

Related of "与URL android共享意图共享图像"

您可以使用共享意图共享图像,但您必须将图像解码为本地化的位图

 Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, "Hey view/download this image"); String path = Images.Media.insertImage(getContentResolver(), loadedImage, "", null); Uri screenshotUri = Uri.parse(path); intent.putExtra(Intent.EXTRA_STREAM, screenshotUri); intent.setType("image/*"); startActivity(Intent.createChooser(intent, "Share image via...")); 

loadedImage是从http://img.androidcookie.com/android/face-03.jpg加载的位图

在这里看到这里

 final ImageView imgview= (ImageView)findViewById(R.id.feedImage1); Uri bmpUri = getLocalBitmapUri(imgview); if (bmpUri != null) { // Construct a ShareIntent with link to image Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); shareIntent.setType("image/*"); // Launch sharing dialog for image startActivity(Intent.createChooser(shareIntent, "Share Image")); } else { // ...sharing failed, handle error } 

然后添加到您的活动:

 public Uri getLocalBitmapUri(ImageView imageView) { // Extract Bitmap from ImageView drawable Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable){ bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { File file = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png"); file.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = Uri.fromFile(file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } 
 Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT,"http://img.androidcookie.com/android/face-03.jpg"); startActivity(Intent.createChooser(intent, "Share Image")); 

将url转换为string格式

 Intent imageIntent = new Intent(Intent.ACTION_SEND); Uri imageUri = Uri.parse("http://img.androidcookie.com/android/face-03.jpg"); imageIntent.setType("image/*"); imageIntent.putExtra(Intent.EXTRA_STREAM, String.valueOf(imageUri)); startActivity(imageIntent);