【问题标题】:Can not save camera's captured photo in application's "files" folder无法将相机拍摄的照片保存在应用程序“文件”文件夹中
【发布时间】:2014-12-23 10:03:10
【问题描述】:

我在应用程序的内部存储“文件”文件夹中创建了一个名为“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);

可能出了什么问题? 有没有办法更改文件夹的权限?

提前谢谢你!

【问题讨论】:

    标签: android permissions camera storage


    【解决方案1】:

    使用 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 中已被弃用
    猜你喜欢
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多