Android模拟器sdcard permisisons不工作

时间:2021-09-14 18:53:29

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

它总是说已安装和可读?假

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.

标记内部和 标记之前的AndroidManifest.xml中。

2 个解决方案

#1


0  

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.

根据设备的不同,我个人发现Environment.getExternalStorage *()在指向的内容中是不可靠的。在这种情况下,它可能指向模拟存储,它似乎不喜欢I / O.我最后只使用“/ sdcard / Movies /”,它比Environment.getExternalStoragePublicDirectory(“Movies”)更有效。

#2


0  

I have no idea why but I recreated the AVD and now its readable.

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

#1


0  

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.

根据设备的不同,我个人发现Environment.getExternalStorage *()在指向的内容中是不可靠的。在这种情况下,它可能指向模拟存储,它似乎不喜欢I / O.我最后只使用“/ sdcard / Movies /”,它比Environment.getExternalStoragePublicDirectory(“Movies”)更有效。

#2


0  

I have no idea why but I recreated the AVD and now its readable.

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