1

I create a folder called "myImage" in my application's Internal Storage "files" folder. When i take a photo with the camera i want the photo to be saved in "files/myImage" folder. It seems that the camera has not the permsission to write in that folder because the folder remains empty. On the other hand, when i create "myImage" folder in the external storage, the photo is saved normally.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
UUID myPhotoGuid = UUID.randomUUID();
myPhotoName = myPhotoGuid.toString();

String dirPath = getActivity().getFilesDir().getAbsolutePath() + File.separator + "myImage";
File myPhotoDirectory = new File(dirPath);
myPhotoDirectory.mkdir();

File f = new File(myPhotoDirectory.toString(), myPhotoName);                    

                // Save the captured image in f file
                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));                    
                startActivityForResult(intent, CAPTURE_IMAGE);

What could be wrong? Is there a way to change folder's permissions?

Thank you in advance!

Fivos
  • 558
  • 8
  • 19

1 Answers1

0

Instead of getFilesDir use getExternalFilesDir.

You might also need to add some permissions:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  • Thank you William but this is not what i need, because i want to write the photo file in my app's Internal Storage "file" folder. – Fivos Dec 23 '14 at 10:24
  • As far as I understand you cannot do what you would like without setting MODE_WORLD_READABLE / MODE_WORLD_WRITEABLE and these constants were deprecated in API level 17 – William Deans Dec 23 '14 at 10:28