0
我遇到问题,希望你能帮助我。Android删除所有以特定词开头的文件
在我的壁纸应用程序中,我将图像保存到SD卡,以便用户可以通过ActionBar共享功能在网上共享它。
这里是不会保存代码:
Uri bmpUri = null;
try {
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");
file.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
bmpUri = Uri.fromFile(file);
} catch (IOException e) {
e.printStackTrace();
}
return bmpUri;
现在,我想,当用户离开活动(这意味着他已经共享的图像或决定不分享删除的图像无论是。这样,它不再需要。)
我试图用这个代码(其上单击按钮方法ATM将其删除,但以后会改变)
case R.id.btn_delete:
// File folder = (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
File folder = new File(Environment.getExternalStorageDirectory() + Environment.DIRECTORY_DOWNLOADS);
File[] filenamestemp = folder.listFiles();
for (int i = 0; i < filenamestemp.length; i++) {
if (filenamestemp[i].getAbsolutePath().toString().contains("share_image_"))
filenamestemp[i].delete();
}
break;
的我看到它的方式,这应该工作......但它不。
我尝试了各种各样的东西,但没有作品。没有错误,什么都没有..但图像仍然存在下载目录。
任何帮助?
我已经尝试过,但它没有工作,所以我评论它,直到我想到的东西。 :) – xsonz 2014-10-28 14:22:22