Every time I try to read the informations of SD Card (removable storage), I get android.system.ErrnoException: statvfs failed: EACCES (Permission denied)
I added permissions in manifest file :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
As minSdkVersion > 23
public static void verifyStoragePermissions(Activity activity) {
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE
);
}
}
The method above is called when the activity is create (it shows the popup and I allow the access)
But when I try to access to the device : (Path = /mnt/media_rw/13F4-1C18)
StatFs stat = new StatFs(path);
I got this error :
java.lang.IllegalArgumentException: Invalid path: /mnt/media_rw/13F4-1C18
at android.os.StatFs.doStat(StatFs.java:46)
at android.os.StatFs.<init>(StatFs.java:39)
.....
Caused by: android.system.ErrnoException: statvfs failed: EACCES (Permission denied)
at libcore.io.Posix.statvfs(Native Method)
at libcore.io.BlockGuardOs.statvfs(BlockGuardOs.java:304)
at android.system.Os.statvfs(Os.java:506)
at android.os.StatFs.doStat(StatFs.java:44)
at android.os.StatFs.<init>(StatFs.java:39)
Have you any idea please how to allow access to REMOVABLE DEVICE ?
Thanks !