0
我需要一种下载图片并将其保存在SD卡中供以后使用的方法。我终于明白了,我只需要一个操作来检查文件是否已经存在。 如果没有,该应用将下载它。如果它退出,我的图像视图将使用它。如何检查Android手机内存中的正确文件?
所以我的问题,只是很单纯:
如何检查在SD文件?
如果我得到这个位置,例如:
String imageInSD = "/sdcard/1.png";
我需要一种下载图片并将其保存在SD卡中供以后使用的方法。我终于明白了,我只需要一个操作来检查文件是否已经存在。 如果没有,该应用将下载它。如果它退出,我的图像视图将使用它。如何检查Android手机内存中的正确文件?
所以我的问题,只是很单纯:
如何检查在SD文件?
如果我得到这个位置,例如:
String imageInSD = "/sdcard/1.png";
您可以使用下面的代码
String sdcardState = android.os.Environment.getExternalStorageState();
String fileName = "yourfilename" + ".png";
if (sdcardState.contentEquals(android.os.Environment.MEDIA_MOUNTED))
{
String destPath = android.os.Environment.getExternalStorageDirectory().toString()+ File.separator +fileName;
File output =new File(destPath);
if(output.exists())
\\it exists-use Imageview
else
\\Download the file accordingly
}
else
\\SDCARD not mounted
就像片段,我需要......现在测试。 – 2012-04-08 06:48:09
这是什么意思“SD卡未安装”? 它不可订购吗? – 2012-04-08 06:49:09
如何处理SD卡状态?我为此得到错误。 – 2012-04-08 06:50:35