Наконец мне удалось полностью удалить файл mp3 из внутреннего хранилища, а также с SD-карты.
Вот код: (может кому-то помочь)
String[] projection = new String[]{BaseColumns._ID, MediaStore.MediaColumns.DATA};
String selection = BaseColumns._ID + " IN (" + id + ")";
try {
final Cursor cursor = context.getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection,null, null);
if (cursor != null) {
// remove from the media database
context.getContentResolver().delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,selection, null);
// remove from storage / sdcard
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
final String name = cursor.getString(1);
try {
final File f = new File(name);
if (!f.delete()) {
Log.e(TAG, "deleteSong: " + title + " can't be deleted");
}
cursor.moveToNext();
} catch (@NonNull final SecurityException ex) {
cursor.moveToNext();
} catch (NullPointerException e) {
Log.e(TAG, "Failed to find file " + name);
}
}
cursor.close();
}
context.getContentResolver().notifyChange(Uri.parse("content://media"), null);
Toast.makeText(context, title + " deleted", Toast.LENGTH_SHORT).show();
} catch (SecurityException ignored) {
}