Capture image without permission with Android 6.0

Try this:

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(getActivity().getApplicationContext().getExternalFilesDir(android.os.Environment.DIRECTORY_PICTURES).getAbsolutePath() + File.separator + "yourPicture.jpg");
Uri uri = Uri.fromFile(file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, url);

This gives you access to an "external" storage writable for camera apps in this case, but the files are just visible from your app. To learn a little bit more about storage spaces in android see https://www.youtube.com/watch?v=C28pvd2plBA

Hope it helps you!


It is possible if you on android 4.4+, you can specify MediaStore.EXTRA_OUTPUT, to be a file under your package-specific directories

Starting in Android 4.4, the owner, group and modes of files on external storage devices are now synthesized based on directory structure. This enables apps to manage their package-specific directories on external storage without requiring they hold the broad WRITE_EXTERNAL_STORAGE permission. For example, the app with package name com.example.foo can now freely access Android/data/com.example.foo/ on external storage devices with no permissions. These synthesized permissions are accomplished by wrapping raw storage devices in a FUSE daemon.

https://source.android.com/devices/storage/


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.