Can not save camera's captured photo in application's “files” folder

拥有回忆 提交于 2019-12-08 07:14:40

问题


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!


回答1:


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" />


来源:https://stackoverflow.com/questions/27618074/can-not-save-cameras-captured-photo-in-applications-files-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!