每次我嘗試讀取SD卡(可移動存儲)的信息,我得到android.system.ErrnoException:statvfs失敗:EACCES(拒絕)讀/寫可移動SD卡(Android模擬器)
我在清單文件添加權限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
作爲的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
);
}
}
的方法,當活動是創建上面被稱爲(它示出了在彈出我允許接入)
但是,當我嘗試訪問該設備:(路徑=到/ mnt/media_rw/13F4-1C18)
StatFs stat = new StatFs(path);
我得到這個錯誤:
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)
你有什麼想法,請如何允許訪問可移動設備?
謝謝!
你想讀什麼樣的信息?這看起來不像是SD卡的路徑。 – greenapps
設備的尺寸(總數,可用尺寸) – Mohamed
你想寫什麼? – greenapps