0

I'm trying to request permissions to take photo with camera app and saving it to file system. I' m using

ActivityCompat.requestPermissions(this,new String[]{
                                     Manifest.permission.CAMERA,
                                     Manifest.permission.READ_EXTERNAL_STORAGE
                     }, PERMISSIONS_MULTIPLE_REQUEST);

But this only shows a dialog to ask user about external storage. If i try to access camera, i get an exception

java.lang.RuntimeException: Unable to start activity ComponentInfo{it.cosmopolitans.around/it.cosmopolitans.around.Boundary.ImageTakenActivity}: android.os.FileUriExposedException: file:///storage/emulated/0/Pictures/Hello%20Camera/IMG_20170709_194415.jpg exposed beyond app through ClipData.Item.getUri()

at this line

startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);

Everything is fine if i run the app on a before-marshmellow device

QuasarLex
  • 75
  • 3
  • 11
  • https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed (your problem has nothing to do with runtime permissions) – CommonsWare Jul 09 '17 at 20:17
  • Thank you. You are right. In fact i'm opening another question about that. Please check it through my profile if you want. – QuasarLex Jul 09 '17 at 22:25

1 Answers1

0

for saving photo result from camera you need WRITE_EXTERNAL_STORAGE permission. try this :

ActivityCompat.requestPermissions(this,
                new String[]{ Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE },
                PERMISSIONS_MULTIPLE_REQUEST);
andri_sasuke
  • 211
  • 3
  • 10