安卓开发删除文件产生0KB文件
安卓开发,删除文件夹产生0KB文件,原因是数据库没有删除该文件的记录,在每次file.delete();后加入该代码即可。
private void deleteFromMediaDatabase(final Context context, final String file) {final String where = MediaStore.MediaColumns.DATA + "=?";final String[] selectionArgs = new String[] {file};final ContentResolver contentResolver = context.getContentResolver();final Uri filesUri = MediaStore.Files.getContentUri("external");// Delete the entry from the media database. This will actually delete media files.contentResolver.delete(filesUri, where, selectionArgs);}