I need to let the user take a picture (from the gallery or from a camera app) with Android 6.0.
Because I don\'t need to control the camera, I wanted to use an intent as
This is possible without either of the CAMERA
and WRITE_EXTERNAL_STORAGE
permissions.
You can create a temporary in your app's cache directory, and give other apps access to it. That makes the file writeable by the camera app:
File tempFile = File.createTempFile("photo", ".jpg", context.getCacheDir());
tempFile.setWritable(true, false);
Now you just need to pass this file as the output file for the camera intent:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempFile)); // pass temp file
startActivityForResult(intent, REQUEST_CODE_CAMERA);
Note: the file Uri won't be passed to you in the Activity result, you'll have to keep a reference to the tempFile and retrieve it from there.