简体   繁体   中英

open failed: EACCES (Permission denied)

I'm getting the following error in a Galaxy J5 (Android 6.0) when trying to save an image:

java.io.FileNotFoundException: /storage/FA49-E5D3/DCIM/Camera/20170311_140435.jpg: open failed: EACCES (Permission denied)

I have the following permissions:

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

In Activity:

    if (Build.VERSION.SDK_INT >= 23) {
        System.out.println("checking permissions...");
        // -------------------------------------- PERMISOS CAMARA -------------------------------------------------
        if (checkSelfPermission("android.permission.CAMERA") != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{"android.permission.CAMERA"}, 137);
            return;
        }
        // ---------------------------------- PERMISOS READ EXTERNAL ---------------------------------------------
        if (checkSelfPermission("android.permission.READ_EXTERNAL_STORAGE") != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{"android.permission.READ_EXTERNAL_STORAGE"}, 139);
            return;
        }
        // ---------------------------------- PERMISOS WRITE EXTERNAL ---------------------------------------------
        if (checkSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, 138);
            return;
        }
    } else {
        System.out.println("API < 23... Skip permissions...");
    }

Note that this is working fine in a Motorola G3 (Android 6.0) saving the image in this path:

/storage/emulated/0/DCIM/Camera/IMG_20170311_115623958.jpg

You are trying to write a file on a micro SD card. But they are read only for apps nowadays. Only a system camera app could have permission to write in the DCIM folder on SD.

Have a look at the second item returned by getExternalFilesDirs(). Your app can write in that app specific directory on SD card.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM