无法将相机拍摄的照片保存在应用程序的“文件"中文件夹 [英] Can not save camera's captured photo in application's "files" folder
问题描述
我在应用程序的内部存储文件"文件夹中创建了一个名为"myImage"的文件夹.当我用相机拍摄照片时,我希望将照片保存在"files/myImage"文件夹中.似乎相机没有权限在该文件夹中写入内容,因为该文件夹仍然为空.另一方面,当我在外部存储中创建"myImage"文件夹时,照片将正常保存.
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?
提前谢谢!
推荐答案
使用getExternalFilesDir代替getFilesDir.
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" />
这篇关于无法将相机拍摄的照片保存在应用程序的“文件"中文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!