Android 模拟器无法写入 SD 卡
我在 AndroidManifest.xml 中添加了这一行:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
但是,当我运行代码写入 sdcard 时,我收到此错误:
02-19 13:24:46.760: E/CameraTest(598): /mnt/sdcard/image.jpg: open failed: EACCES (Permission denied)
如何解决此问题?
编辑:我正在使用添加了 SDCard 的 Android 模拟器。
EDIT-2:我知道现在的问题是什么:我调用了函数Environment.getExternalStorageState()
并且我被“删除”了。任何人都知道如何解决此问题并使状态MEDIA_MOUNTED
谢谢!
I have added this line in the AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
However, when I run code to write to the sdcard , I get this Error:
02-19 13:24:46.760: E/CameraTest(598): /mnt/sdcard/image.jpg: open failed: EACCES (Permission denied)
How do I solve this problem?
EDIT: I am using the Android Emulator with SDCard added.
EDIT-2: I know what the problem is now: I have called the function Environment.getExternalStorageState()
and I get "removed". Anyone knows how to fix this and make the state MEDIA_MOUNTED
Thank You!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好的,我已经解决了这个问题。这是我在安装 SD 卡时遇到的问题,并且 Android 不允许路径中存在空格!
这是一个很好的遵循过程(如果也使用 eclipse): http://www.brighthub .com/mobile/google-android/articles/33240.aspx
注意:如果路径中有空格,请将 SD 卡映像文件移动到其他位置,然后使用 SD 卡和所有内容运行模拟器命令应该可以正常工作!
Ok So I have solved this. It was a problem I faced with mounting the sdcard and that android doesn't allow spaces in the path!
Here is a good procedure to follow (if eclipse is also used) : http://www.brighthub.com/mobile/google-android/articles/33240.aspx
NOTE: in case the path has a space in it, move the sdcard image file to somewhere else and then run the emulator command with the sdcard and everything should work fine!
事情可能比这更简单。我错过了配置模拟器,使其具有 SD 卡。当我在设备中添加 SD 卡后,一切顺利。
问候,
乔纳斯
It might be more simple than that. I missed to configure the emulator so that it had a SD-card. Once I added a SD-card in the device, everything went well.
Regards,
Jonas
我注意到,如果您使用 Android 6.0 模拟器,Android 为 (Marshmallow) 添加了新的权限模型,则可能会出现此问题。
技巧:如果您的目标版本为 22 或更低版本,您的应用程序将在安装时请求所有权限,就像在运行 Marshmallow 以下操作系统的任何设备上一样
I notice that this problem can occur if you are using an Android 6.0 emulator, Android added new permission model for (Marshmallow).
Trick: If you are targeting version 22 or below, your application will request all permissions at install time just as it would on any device running an OS below Marshmallow
我清除了我用来尝试分享图片(Pixlr)的应用程序的缓存,一切都很好。
I cleared the cache for whichever application I was using to try and share out the picture (Pixlr) and it was fine.