Recording to Micro SD Card in Android 6

In my application, I download some files from the Internet. I give a choice where to store them, internal storage or an external SD card. Before Kitkat, I could write without problems. In Kitkat, it was blocked, if the application is not a system application or the phone is rooted, I try to get it to work with Lollipop and Marsmallow.

I have the following rights:

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

Test device - Samsung Galaxy S5 with 6.0.1 and an external SD card.

I retrieve the list of repositories by reading "/ proc / mounts". It returns to me "storage / emulation / 0" and "Storage / 7074-XXXX"

For Marshmallow, I also check access as such:

private static final int REQUEST_EXTERNAL_STORAGE = 200;
private static String[] PERMISSIONS_STORAGE = {
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.WRITE_EXTERNAL_STORAGE
};



public static void VerifyStoragePermissions(Activity activity) {
    if(android.os.Build.VERSION.SDK_INT >= 23) {
    int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);

    if (permission != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(
                activity,
                PERMISSIONS_STORAGE,
                REQUEST_EXTERNAL_STORAGE
        );
    }
    }
}

The onRequestPermissionsResult procedure tells me that I have write access. It does not show a confirmation screen, etc.

"storage/emulated/0", , . "open failed: EACCES (Permission denied)"

, , SD-, . , .

+4

All Articles