0

Introduction and background

Hi, I have a bitmap created by my application, I wish for this bitmap to be sent to any apps that can handle the mime type "image/png" and the action ("ACTION_SEND"). Basically, allow the bitmap image to be sent to someone by another component like email and messaging etc.

What I got now

At moment my app saves the bitmap image to external memory within a directory I made. Each bitmap saved is scanned by the MediaScannerConnection and using the OnScanCompleteListener, I use the obtained Uri to build the implicit intent. This works fine.

My question

I am trying to cater for users who do not have external memory or have the setting ticked where they do not want any images saved/stored (just for that instance and gone when they close the app). So do I need to actually save an image in memory and get a Uri in order to pass a bitmap image as a implicit intent.

Many thanks for reading.

Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
Ersen Osman
  • 7,067
  • 8
  • 47
  • 80

1 Answers1

1

No, you dont need to save that image anywhere. Just get the filepath from the Bitmap:

String path = Images.Media.insertImage(context.getContentResolver(), bitmap,"abcd", null);

then get a valid Uri from it:

Uri image = Uri.parse(path); 

and add this Uri to your Intent like this:

intent.putExtra(Intent.EXTRA_STREAM,  image);

Done!

Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
  • Hi, thank you for the reply. I am trying it now. Will let you know. – Ersen Osman Mar 02 '15 at 14:01
  • Hi, this seems to still save the picture in storage. It stores it in /storage/emulated/0/DCIM/Camera. – Ersen Osman Mar 02 '15 at 14:09
  • the `bitmap` is stored in memory, but you dont have to store it there, the OS does that for you :) – Yash Sampat Mar 02 '15 at 15:50
  • So is there any way I can have it where nothing is saved in internal or external storage. The only way I think I can do it is if I delete the image when its done because I have a path – Ersen Osman Mar 02 '15 at 17:09
  • yes that can be done ... you can call `startActivityForResult()` and after the `ACTION_SEND` is done, you can delete the image at the path location – Yash Sampat Mar 02 '15 at 17:35