In my android app, I have a bitmap (say b) and a button. Now when I click on the button, I want to share the bitmap. I am making use of the below code inside my onClic
As CommonsWare stated you need to get the URI to the bitmap and pass that as your Extra.
String bitmapPath = Images.Media.insertImage(getContentResolver(), bitmap,"title", null);
Uri bitmapUri = Uri.parse(bitmapPath);
...
intent.putExtra(Intent.EXTRA_STREAM, bitmapUri );
A solution in Kotlin with a timestamp in the image's filename:
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())
val imagePath = MediaStore.Images.Media.insertImage(
context?.contentResolver,
bitmap,
"img_$timeStamp",
null
)
val shareIntent = Intent(Intent.ACTION_SEND).apply {
type = "image/*"
putExtra(Intent.EXTRA_STREAM, Uri.parse(imagePath))
}
context?.startActivity(Intent.createChooser(shareIntent, null))