写SD卡不工作 [英] writing to sdcard not working
问题描述
我运行Android在Eclipse中。以下行(从Camera.demo)
I am running Android in Eclipse. the following line (from Camera.demo)
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg",
System.currentTimeMillis()));
将失败并返回以下错误: -
fails and returns the following error:-
FileNotFound - permission denied.
有什么我可以做纠正呢?我假设的SD卡目录是在模拟器present。
谢谢
罗恩
Is there anything I can do to correct this? I have assumed that the sdcard directory is present in the emulator. Thanks Ron
推荐答案
在正在运行的AVD必须用支持SD卡进行显式配置,或者它的行为就好像没有一个。更多信息这里。
The AVD you're running has to be explicitly configured with SD card support or it will behave as if there isn't one. More information here.
您的应用程序也需要 WRITE_EXTERNAL_STORAGE
的权限。
Your application also needs the WRITE_EXTERNAL_STORAGE
permission.
旁注:你应该叫 Environment.getExternalStorageDirectory()
来获取SD卡中的路径,而不是硬编码 / SD卡$的C $ C>。它返回
空
如果没有可用存储空间。您可以使用返回值 canWrite()
方法来确定它实际上是东西,你可以将其用于存储。
Side note: You should be calling Environment.getExternalStorageDirectory()
to get the SD card's path instead of hard-coding /sdcard
. It returns null
if there's no storage available. You can use the canWrite()
method on the returned value to determine if it's actually something you can use for storage.
这篇关于写SD卡不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!