I'm trying to use ACTION_IMAGE_CAPTURE to get an image from Camera. What places is safe to use as the EXTRA_OUTPUT ?
The only one I've found myself is SdCard, but it seems inconvenient to me (I need a permission, and user has to have an SdCard). Is there another place, I can use?
You could use Activity.getCacheDir().
Related
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).
Is there a way to use the StorageActionFramework ACTION_OPEN_DOCUMENT intent to request info for a specific file? More specifically, I have a URI for a particular file, which I obtained from MediaStore. I would like to find out if it has write access and, if so, delete it. Further, I'd like to do this without any UI (none is needed in this particular context).
The documentation says how to do it for a class of files using intent.addCategory (Intent.CATEGORY_OPENABLE), for example. And to restrict it to a certain type of file, intent.setType ("image/*"), for example. But I don't see anything to restrict it to a specific file.
Also, I realize that once you receive a set of files from the StorageActionFramework, you can view properties for individual files.
It appears that if I could use ACTION_OPEN_DOCUMENT to get the SAF's URI, I could then use DocumentsContract.deleteDocument() to delete it.
More Context
In my situation, the user has invoked the camera app from within my app and taken one or more pictures. My code then queries the MediaStore to determine the file name(s) for the new image(s). Then I desire to move the file(s) to a directory specific to my app. This works fine for files located in "internal" and "external" storage but not for removable storage.
In the long run, this solution is inadequate as clearly it will use to much permanent storage (although that is mitigated by the fast pace which storage size is increasing). However my app does need control over image files which are taken via the app and, thus, leaving them on the removable storage will potentially break the app.
Another complicating factor is the lack of an Android API for taking multiple photos and saving them to a prescribed location. There is such an API for taking a single photo but that will not work for my application. Thus, I am relegated to letting the camera app save its files where it wants to and then moving them afterward.
Some other apps simply make a copy of photos and store the copy in a private directory. I could do that but that exacerbates the storage problem even more. The long term solution will probably be using cloud storage in combination with a local private cache.
Is there a way to use the StorageActionFramework ACTION_OPEN_DOCUMENT intent to request info for a specific file?
No. For starters, the Storage Access Framework has little to do with files.
The closest thing that would fit the overall structure would be if you could supply a starting Uri, to allow users to choose and open a document nearby that one. That would be a nice feature but is not supported.
The documentation says how to do it for a class of files using intent.addCategory (Intent.CATEGORY_OPENABLE), for example.
No. CATEGORY_OPENABLE means that the Uri that you get back should work with openInputStream(), openOutputStream(), and related methods, and that a query() on the Uri should be able to return the OpenableColumns. It has little to do with files.
And to restrict it to a certain type of file, intent.setType ("image/*")
That limits the content to a particular MIME type (or wildcard). It has little to do with files.
I would like to find out if it has write access and, if so, delete it
You might have write access to change the contents, via openOutputStream(). I am not aware that you have a means of deleting the underlying content.
Further, I'd like to do this without any UI
The only reason to use ACTION_OPEN_DOCUMENT is to show a UI, to allow the user to choose a piece of content.
My code then queries the MediaStore to determine the file name for the new image
Since there is no requirement for a camera app to update the MediaStore, this does not seem like it will be especially reliable.
Another complicating factor is the lack of an Android API for taking multiple photos and saving them to a prescribed location. There is such an API for taking a single photo but that will not work for my application
Since there is no requirement for a camera app to allow the user to take multiple photos in succession, this does not seem like it will be especially reliable.
I've seen that Android automatically generates a thumbnail when taking a photo, and saves it as an extra with the key "data". Is it possible to disable that action, as to save space in the device?
I've seen that Android automatically generates a thumbnail when taking a photo, and saves it as an extra with the key "data".
No, it does not. Camera apps may generate thumbnails and put them in a data extra in the Intent used with setResult(). Android, the operating system, does not.
Is it possible to disable that action, as to save space in the device?
I do not know what "space" you think you will "save". That thumbnail is held briefly in system RAM. It is not stored on disk.
If you are a programmer, and if you are writing an Android app, and if you are using an ACTION_IMAGE_CAPTURE Intent with startActivityForResult() to invoke a third-party camera app, then you can include EXTRA_OUTPUT to indicate where you want a full-sized image to be written. According to the ACTION_IMAGE_CAPTURE specification, the data extra is not needed in that case. Some camera apps will then skip that extra.
However, developers of third-party camera apps are welcome to do whatever they want. If they want to create the data extra on every ACTION_IMAGE_CAPTURE request, that is their decision to make, as they are the ones writing the camera apps.
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.
i am developing an application where i need to capture the pictures from camera and save them with in application like in this location "/data/data/com...../images" - what i want to know is this the right approach . if not please suggest but my images should not be available to other app's.
Thanks and Regards,
puneeth
I think every approach have their drawbacks. If the picture should always be there (unless delete through app), I feel it may not be best approach. Otherwise it is Ok to use this approach (which is what I am doing too). Only caution I took was, if picture was deleted by someone, always have a default picture to display there (which saves application crash and other alignment issues).
You’re talking about the Context.getFilesDir() directory. Note that, on older phones with separate SD card storage, this area is likely to be quite limited in size, so be careful about saving lots of images here. You may want to use getExternalCacheDir() or getExternalFilesDir() instead.