【问题标题】:Android - libcore.io.ErrnoException: open failed: EACCES (Permission denied)Android - libcore.io.ErrnoException:打开失败:EACCES(权限被拒绝)
【发布时间】:2014-12-30 15:56:08
【问题描述】:

我正在尝试根据here 的说明将图像写入文件。但是,我得到了这个例外: libcore.io.ErrnoException: open failed: EACCES (Permission denied) 这是我的代码,显然会弹出此异常:

private File createImageFile(int side) throws IOException {
        String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "";
        if (side==1) {
            imageFileName = "Front_"+timestamp;
        } else {
            imageFileName = "Side_"+timestamp;
        }
        File storageDir = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
                imageFileName,
                ".jpg",
                storageDir
        );

        // Save the file
        mCurrentPhotoPath = "file:"+image.getAbsolutePath();
        return image;
    }

提前感谢您的帮助。

【问题讨论】:

    标签: android permission-denied


    【解决方案1】:

    问题是应该是 File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 而不是 File storageDir = this.getExternalFilesDir(null);

    【讨论】:

      猜你喜欢
      • 2021-12-23
      • 2021-07-02
      • 2016-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-25
      • 2015-01-12
      • 2016-06-14
      相关资源
      最近更新 更多