Share Image From URL Dynamically Android

using Picasso

i put getLocalBitmapUril in the same class “Util”.

just call shareImage(YOUR_URL, this);

Example URL: “https://content.linkedin.com/content/dam/me/learning/blog/2017/Junepics/Money.jpg

static public void shareImage(String url, final Context context) {
Picasso.with(context).load(url).into(new Target() {
@Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/*");
i.putExtra(Intent.EXTRA_STREAM, Util.getLocalBitmapUri(bitmap, context));
context.startActivity(Intent.createChooser(i, "Share Image"));
}
@Override public void onBitmapFailed(Drawable errorDrawable) { }
@Override public void onPrepareLoad(Drawable placeHolderDrawable) { }
});
}
static public Uri getLocalBitmapUri(Bitmap bmp, Context context) {
Uri bmpUri = null;
try {
File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png");
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;
}

reference : https://stackoverflow.com/questions/16300959/android-share-image-from-url