Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法将相机拍摄的照片保存在应用程序的“文件”文件夹中_Android_Permissions_Camera_Storage - Fatal编程技术网

Android 无法将相机拍摄的照片保存在应用程序的“文件”文件夹中

Android 无法将相机拍摄的照片保存在应用程序的“文件”文件夹中,android,permissions,camera,storage,Android,Permissions,Camera,Storage,我在应用程序的内部存储文件文件夹中创建了一个名为myImage的文件夹。当我用相机拍照时,我希望照片保存在files/myImage文件夹中。似乎相机没有权限写入该文件夹,因为该文件夹仍然为空。另一方面,当我在外部存储器中创建myImage文件夹时,照片会正常保存 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); UUID myPhotoGuid = UUID.randomUUID(); myPhotoName = myPh

我在应用程序的内部存储文件文件夹中创建了一个名为myImage的文件夹。当我用相机拍照时,我希望照片保存在files/myImage文件夹中。似乎相机没有权限写入该文件夹,因为该文件夹仍然为空。另一方面,当我在外部存储器中创建myImage文件夹时,照片会正常保存

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);
有什么不对劲吗? 有没有办法更改文件夹的权限


提前谢谢你

使用getExternalFilesDir代替getFilesDir

您可能还需要添加一些权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

谢谢你,威廉,但这不是我需要的,因为我想在我的应用程序的内部存储文件夹中写入照片文件。据我所知,如果不设置MODE_WORLD_READABLE/MODE_WORLD_WRITEABLE,你就无法做你想做的事,这些常量在API级别17中被弃用