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