I insert an image via:
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, filename);
values.put(Images.Media.DATE_ADDE
As stated in the comments, the accepted answer uses a lot of memory. While MediaScannerConnection doesn't have a "deleteFile" method, just pass in the the old file path to the "scanFile" method once you've deleted the file. The media scanner will rescan and remove the media.
tested on N5. Android 4.4.
EDIT: Other have stated this doesn't work on 4.2
new AsyncTask(){
@Override
protected Void doInBackground(Void... params) {
String filePath = recording.file.getAbsolutePath();
recording.file.delete();
MediaScannerConnection.scanFile(context,
new String[]{filePath}, null, null);
return null;
}
}.execute();