Reference: Http://www.sandersdenardi.com/querying-and-removing-media-from-android-mediastore/
To delete from the media table:
private void Delsourcefile (final String FilePath) {
Threadfactory.getnormapool (). Execute (new Runnable () {
@Override
public void Run () {
String[] Retcol = {mediastore.audio.media._id};
Cursor cur = mactivity.getcontentresolver (). Query (
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
Retcol,
MediaStore.MediaColumns.DATA + "= '" + FilePath + "'", null, NULL);
if (cur.getcount () = = 0) {
Return
}
Cur.movetofirst ();
int id = cur.getint (cur.getcolumnindex (mediastore.mediacolumns._id));
Logutil.getlog (). E ("id=" + FilePath);
Cur.close ();
try {
Uri uri = Contenturis.withappendedid (MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
ID);
Mactivity.getcontentresolver (). Delete (URI, NULL, NULL);
} catch (Exception e) {
E.printstacktrace ();
}
}
});
}
Delete from Local:
/**
* Delete files from SD card
*/
public static voidDeleteFile (file file) {
if (environment.Getexternalstoragestate (). Equals (Environment.media_mounted)) {
if (file.exists ()) {
if (File.isfile ()) {
File.delete ();
}
If it's a directory
else if (File.isdirectory ()) {
//all documents under the Declaration directory files[];
File files[] = file.listfiles () ;
for (int i = 0; I < files. length// Traverse all files under directory
deletefile (Files[i]) ; //each file with this method to iterate
}
File.delete () ;
}
} /span>
Remove media files from Mediastorehe and SD