Environment.getExternalStorageDirectory()上的模拟器 [英] Environment.getExternalStorageDirectory() on the emulator

查看:1392
本文介绍了Environment.getExternalStorageDirectory()上的模拟器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读取和写入图像到外部存储在我的应用程序。从我读了下面是正确的方式来获得对目录的句柄。

I want to read and write images to the external storage in my app. From what I read the following is the correct way to get a handle on the directory.

 File externalStorageDir = Environment.getExternalStorageDirectory();
 File picturesDir = new File(externalStorageDir, "Pictures");

不过...

However ...

 picturesDir.exists(); // == null
 picturesDir.mkdir(); // == false

这是因为我使用模拟器?

Is this because I'm using the emulator?

推荐答案

您可能希望确保您已外部存储启用:

You might want to make sure you have external storage enabled:

在Eclipse中,选择Window> Android SDK和AVD管理。选择适当的AVD,然后单击编辑。

In Eclipse, go to Window > Android SDK and AVD Manager. Select the appropriate AVD and then click Edit.

请确保您启用了SD卡的支持。如果不这样做,点击新建按钮,选择支持SD卡选项。

Make sure you have SD card support enabled. If you do not, click the "New" button and select the "SD Card Support" option.

编辑:还需要添加

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

到清单。

这篇关于Environment.getExternalStorageDirectory()上的模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆