Is it possible to capture a camera image and use it in my code, but not have the image saved on the device? I need the image for sending to an API, but I have no need for the user to have the file afterwards. Can this be done?
Asked
Active
Viewed 1,741 times
2
-
What kind of object does the API accept? – ygesher Jan 29 '15 at 21:10
-
I have to provide a jpeg with min dimension and max dimension and quality level specified (it's an image recognition API). I've already developed code to handle all that using images already in the image folder. I'd rather not leave the image in the folder as a remnant after they use the app. I could always delete it, but was just wondering if I could process a file directly from a click event and not save anything. – Kent Lauridsen Jan 29 '15 at 21:28
-
1You could also set an Alarm with AlarmManager to delete it later. Incase your app crashes or is closed. – Charles Ritchie Jan 29 '15 at 21:30
-
that's a thought for if I have to (or end up deciding to) go the "delete afterwards" route.. although if they reboot their phone before it gets a chance to run it will still be there it seems – Kent Lauridsen Jan 29 '15 at 21:35
-
"android.intent.action.BOOT_COMPLETED" is your friend, I use it to schedule a cleanup service on reboot, on a couple of my apps. I set a user pref once cleanup is complete and check this value on boot. It is probably a good idea to not have cleanup service scheduled immediately as many apps already do this and it slows down phone straight after boot(very annoying). so set it for a few minutes into the future. – Charles Ritchie Jan 29 '15 at 21:40
2 Answers
2
This is not a good idea, as there is too much overhead when handling the full size image in RAM. I would personally just create a scaled down preview to put in UI(if needed), then upload original(saved on SD) image and delete afterwards.
Some devices will force the images into the gallery. This will help you with said problem
Here is my edited answer in regard to how i would do it.
- Save image to disk and ensure it is encoded correctly for the API you are using.
- Start upload service when network connection is available (if necessary).
- Either delete image from service or schedule an Alarm to start service and deal with it later

Community
- 1
- 1

Charles Ritchie
- 2,283
- 2
- 16
- 21
-
I don't think holding the decompressed data in RAM for a few moments while it gets uploaded is such a terrible thing. Do you have any data to back up this notion? – ygesher Jan 29 '15 at 21:09
-
1When programming for Android I always try to ensure I use the least resources possible, while still maintaining a fluid user experience. It is just good programming practice. Also this would allow one to do the upload on a separate thread with a service etc, while keeping the UI free to do UI like things. It is just a more modular approach. I mean what if the connection to the server is really slow or gets interrupted. i would handle this all in a service, neat, easy, extensible. – Charles Ritchie Jan 29 '15 at 21:17
-
I agree that this is definitely something that should be shunted off the main UI thread, but that still keeps it in RAM just the same... – ygesher Jan 29 '15 at 21:22
-
1I would not have it in RAM, but save to disk and STREAM data at a convenient time, what if there is no data connection? This way I do not have to have the whole image in RAM. – Charles Ritchie Jan 29 '15 at 21:26
-
-
I had been planning on the user being notified to resnap pic if server upload fails, but actually that error mode points squarely at saving the image normally and then only setting the delete process (as you've laid out above) into motion once I've got assurance from the API that it is satisfied and the transaction is complete. Thanks everyone for the help. I'll report back with how this goes. – Kent Lauridsen Jan 29 '15 at 21:46
-
thanks also for pointing out the obvious use case of not having connectivity at time of image capture.. I don't want user to even have to worry about that.. .thanks. – Kent Lauridsen Jan 29 '15 at 21:49
-
Awesome, good luck don't forget to cleanup on boot. Contact me if you need any help. – Charles Ritchie Jan 29 '15 at 21:49
0
if u r using native camera activity
- capture the image on file
- get the bitmap of the image from the file
- delete the file
(u can save the image in hidden directory {{its name should start with dot
.hidden_dir/myimg.jpg }} )

Diaa Saada
- 1,026
- 1
- 12
- 22
-
thanks.. I thought about doing this, but still would like to know my options and ramifications of each. very helpful comments so far. – Kent Lauridsen Jan 29 '15 at 21:30
-
I would give you a vote up for the idea of hidden directory, but don't have the required 15 points yet.. thanks though – Kent Lauridsen Jan 29 '15 at 21:48