简体   繁体   中英

Android emulator sdcard permisisons not working

I've read many posts about this but nothing seems to solve the problem.

I've created a simple app that basically consists of:

    Log.d("RSE", Environment.getExternalStorageState());
    Log.d("RSE", "Readable? " + Environment.getExternalStoragePublicDirectory("Movies").canRead());

It always says mounted and Readable? false Readable? false

When I try to do anything more, I get a permission denied error.

I've added

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

inside AndroidManifest.xml inside the <manifest> tag and before the <application> tag.

Depending on the device, I've personally found Environment.getExternalStorage*() to be unreliable in what it points to. In this case, it's probably pointing to the emulated storage which doesn't seem to like I/O. I ended up just using "/sdcard/Movies/" which worked far more reliably than Environment.getExternalStoragePublicDirectory("Movies") ever did.

我不知道为什么,但是我重新创建了AVD,现在可以读取它了。

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