In my app I am downloading some files from Internet. I am giving choice where to store them, internal storage or external sd card. Till Kitkat, I could write without problems. In Kitkat it was blocked unless app is system app or phone is rooted, I am trying to make it work with Lollipop & Marsmallow.
I have such permissions:
<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 is Samsung Galaxy S5 with 6.0.1 and external SD card.
I retrieve list of storages by reading "/proc/mounts". It returns to me "storage/emulated/0" and "storage/7074-XXXX"
For Marshmallow, I also check the access like that:
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
);
}
}
}
onRequestPermissionsResult procedure tells me that I have write access. It does not show a confirmation screen etc.
If I select "storage/emulated/0" I can write to this directory, but not the second. I receive error "open failed: EACCES (Permission denied)"
What I want is mainly encourage users to write those files to external SD card if it is present. Please help.