Android delete all files starting with particular word -
Android delete all files starting with particular word -
i have problem , hope can help me out.
in wallpaper app, saving image sdcard user can share online via actionbar share function.
here code saving:
uri bmpuri = null; seek { 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); } grab (ioexception e) { e.printstacktrace(); } homecoming bmpuri;
now, trying delete image when user leaves activity (which means shared image or decided not share. either way, not needed anymore.)
i trying delete code (its on button click method atm, alter later)
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(); (int = 0; < filenamestemp.length; i++) { if (filenamestemp[i].getabsolutepath().tostring().contains("share_image_")) filenamestemp[i].delete(); } break;
the way see it, should work...but doesn't.
i tried sorts of things, nothings works. no errors,nothing..but image still nowadays in downloads directory.
any help?
i think getting wrong directory written files
you reading files by
file folder = new file(environment.getexternalstoragedirectory() + environment.directory_downloads);
instead of:
file folder = (environment.getexternalstoragepublicdirectory(environment.directory_downloads));
these directories not same.
hope helps, if need else tell me ;)
android delete-file
Comments
Post a Comment