Keep Camera from saving photo - android

I have an application that captures pictures by dispatching an intent. Upon return of control to the activity, I retrieve the intent, extract the data, transform it into a bitmap and use it in my application. Just some straight forward code.
The pictures taken are subject to some privacy obligations and my application takes care to delete all data. The problem is that all pictures taken by the Camera application seem to automatically be saves into internal storage. I was successful in deleting screenshots taken by the device and by clearing all thumbnails. What remains to be done is keep the Camera application from storing picture in the first place.
The problem as I see it is that I relinquish control to the application and, hence, cannot influence it in any way. I tried launching ACTION_IMAGE_CAPTURE_SECURE but that failed. I would much prefer the approach of keeping the application from storing the image to the approach of having to scan the internal storage location for images and delete them as I tried it and failed.
Note: I have assigned all the right permissions. Should you need code, I will be happy to post it but there is nothing that cannot be found already in other threads. If there is no solution to my preferred approach, how would I go about deleting all images located in the internal storage at DCIM\Camera? Thank you!

If you need to override that behavior, don't take the pictures via intent. Take them yourself, using the android.hardware.Camera API.

Related

Taking photos and videos in app and sending the data between app components

This question is a bit on the broader side of things so I will not provide any specific code because it will be irrelevant.
I have an app that allows the user to take photos, and hopefully videos in the future. Currently it happens as follows:
The user opens a dialog inside one activity.
The user can choose to take an image, which sends him to a CameraActivity (using CameraX).
The user takes an image, the image is saved locally in the app files and the result code and path to the image are sent to the calling activity.
The dialog overrides onActivityResult and loads the image from the internal storage and displays it.
The user can choose to delete the image or cancel the entire dialog, on both cases the image needs to be removed from the storage.
(The process can happen with multiple images inside the same dialog)
I wanted to ask you if it seems like a reasonable implementation or there are other architectures\android components you would recommend using. More specifically I'm worrying about the time it takes to save the image locally if I will want to increase the quality or do the same process with videos which are much heavier (I've already seen a considerable extra time if I want to save it as png instead of jpeg).
The two improvements to the system that I can think of:
Using something akin to ViewModel for saving the bitmap and having the data available when moving back to the dialog from the camera activity.
Saving the data to the cache instead on the local storage (and only save it to the local storage if the user approves in the dialog).
But I'd like to hear suggestions, are there any particular APIs that I should know about? or a recommended change to the architecture?
The current system will simply be too slow for higher quality images or a video, and I'm not sure how best to improve things and also not make the app too consuming on the resources side.

Take a picture and get bytes without saving on disk

Is it possible to take a picture and get the image as byte array without saving it?
All I want is, take an in memory picture. I don't want to save it. Also i plan to use other camera activity to take the picture (i mean, i don't want to implement my own camera logic)
Please note, I know that I can take a picture, read bytes and delete it. But I am looking if I can avoid this saving and deleting part, instead directly get the image in an in memory byte array.
Is it possible to take a picture and get the image as byte array without saving it?
That is the behavior of the android.hardware.Camera API, the android.hardware.camera2 API, and third-party libraries that simplify those APIs (e.g., Fotoapparat, CameraKit-Android).
i plan to use other camera activity to take the picture
If by "other camera activity", you mean a third-party camera app (e.g., via ACTION_IMAGE_CAPTURE), that will be difficult and unreliable. At best, you could try to use a content Uri pointing to a ContentProvider that you write that only holds onto written streams in memory. I would expect you to run out of heap space. Plus, not all camera apps will support a content Uri for EXTRA_OUTPUT (though they should).

Android:is it possible to share the bitmap image without saving it

I am creating bitmap image in my application and i dont want to save it on phone. If user want he can share it with other apps.I tried many things but m not able to share the image with other app without saving it. Is there really any way by which we can share the image with other android application without saving it? or we must have to save it first and then share. Kindly suggest.
The Bitmap saved is not on disk, but only in RAM. Other apps are not allowed to read your's app's allocated RAM. The ways for your app to export volatile data are:
Write byte data to a large Parcel, and put it in an Intent extra.
provide data over to a network socket or via a custom content/file provider etc.
But even for these methods to work, you need other apps to know how to fetch data. Which is very unlikely unless the other app is also programmed by you.

Prevent ACTION_IMAGE_CAPTURE from saving a picture

I am using an ACTION_IMAGE_CAPTURE Intent to take photos, which I then manipulate.
I want to save only the final image. How can I prevent photos from being saved immediately after photo is taken?
Your best bet is to copy the image returned in the result Intent and then use a ContentResolver to delete the original image. The different OEMs, of course, have different camera implementations. The procedure I described has worked with all of them from my testing.
This is assuming that there's some reason that you can't just manipulate the original image and write over it.
If you use a third-party app to take the picture for you:
The third-party app has to save the picture, because otherwise it cannot get the picture to you
The third-party app can do whatever else it wants, because it was written by somebody else, and they can do what they want
If that is unacceptable, do not use third-party apps to take the picture for you.

Detecting photo action in android

Hey I'm stuck with this problem for quite a while
I need to have a backround activity in android which will be running to detect any photo/video activity, the minute a photo or video is taken it should make an entry into a text file:
The entry should look like this : [uri_of_new_photo, time, gps-location]
What are the possible ways in which i can achieve this, I was looking at the BroadcastReciever, but was not sure if that would work.
Are there any tutorials/links which can give me a solution. A direct solution to this problem would be great!! (rather than alternatives, as this is a small part of a bigger project)
What are the possible ways in which i can achieve this
Technically, it's not possible. Anyone is welcome to write a camera application that takes photos or videos and does not tell you about them.
I was looking at the BroadcastReciever, but was not sure if that would work.
I am not sure what "the BroadcastReceiver" is that you are referring to.
You are welcome to use FileObserver to try to monitor likely places for photos and recorded videos. However, there is no guarantee that apps will write their photos or recorded videos in the places that you are looking. And, just because there is a new file in one of those directories does not mean that the user took a photo or recorded a video -- they could have simply copied a file into that directory, or obtained the file from the Internet (e.g., Flickr sync). And, this will only work while your app is running.
You are welcome to use a ContentObserver on MediaStore. It will suffer from the same basic problems as would the FileObserver approach that I mentioned.
If you want to reliably log information about the time and location of photos and videos, write your own camera app.

Categories

Resources