外部写入权限被拒绝

时间:2014-11-28 03:46:58

标签: android io permissions

我正在尝试使用保存到文件的图片来学习如何读取/写入外部驱动器(甚至是板载驱动器)。此代码段直接来自Android开发人员API,我收到EACCES Permission Denied错误。我有写权限并在清单中使用相机硬件。我已经了解了为什么会这样,但我还没有看到一个能够帮助我的解决方案。我的设备根深蒂固,所以我认为我可以绕过这个问题,但显然不是。由于我是Android的这一部分的新手,我可能没有意识到我应该对这个问题做些什么。非常感谢任何帮助!

//set up an intent to take a picture
private void dispatchTakePictureIntent() {

    log("in dispatchTakePictureIntent()");
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            log("Exception caught.  Aborting image creation" + ex);
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

//set up a file for the impending picture
private File createImageFile() throws IOException {

    log("in createImageFile()");
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
        imageFileName,  /* prefix */
        ".jpg",         /* suffix */
        storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = "file:" + image.getAbsolutePath();
    return image;
}

    //Snippet of manifest file
<uses-sdk
    android:minSdkVersion="18"
    android:targetSdkVersion="18" />

<uses-feature 
    android:name="android.hardware.camera"
    android:required="true" />

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

1 个答案:

答案 0 :(得分:0)

结束必须删除

android:maxSdkVersion="18"

从清单文件中。