Search code examples
androidandroid-cameraandroid-permissions

Use Camera on Android 8 without WRITE_EXTERNAL_STORAGE permission


I am trying to make my app capture an image and send it over to the server, without storing in the filesystem.

If I do it like this:

intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, SOME_REQUEST_CODE);

In onActivityResult I can extract the image via

Bitmap photo = (Bitmap) data.getExtras().get("data");

but this gives me only a thumbnail.

From the documentation it seems that (one of the?) ways to get a full HD image is by instructing the camera app to store the image at some external location, by adding

intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

However this obviously requires WRITE_EXTERNAL_STORAGE

Considering I don't need the image to be stored in the filesystem, as I am sending it via network anyway, I believe asking for extra storage permission is against "ask only what you need" principle. So is there a possibility to somehow get a full hd image in memory and avoid asking the user for storage permission? Perhaps there exists some special FileProvider path type for such cases?

I have found this answer: Capture image without permission with Android 6.0 but it doesn't use FileProvider (which I have to use on Android 8) and doesn't seem to be applicable to my case.

Thanks.


Solution

  • Just use a file provider and save to getFilesDir or getExternalFilesDir and you do not need WRITE permission or ask the user..