use any image library that gives bitmap from an image link
(Picasso, Glide, Coil**,..)
fun shareImageFromURI(url: String?) {
Picasso.get().load(url).into(object : Target {
override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "image/*"
intent.putExtra(Intent.EXTRA_TEXT, "Your awesome text");
intent.putExtra(Intent.EXTRA_STREAM, getBitmapFromView(bitmap))
startActivity(Intent.createChooser(intent, "Share Image"))
}
override fun onPrepareLoad(placeHolderDrawable: Drawable?) { }
override fun onBitmapFailed(e: java.lang.Exception?, errorDrawable: Drawable?) { }
})
}
on click of the share button, you can call this function and pass the image link to it, it will start intent after downloaded the image
update
fun getBitmapFromView(bitmap:Bitmap):Uri{
val bitmapPath = Images.Media.insertImage(getContentResolver(),
bitmap,"title", null);
return Uri.parse(bitmapPath);
}