Android examples for android.media:Audio
delete Audio In Folder From Media Provider
import java.io.File; import java.util.ArrayList; import java.util.List; import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.MediaStore.Audio; import android.util.Log; public class Main { private static final String t = "MediaUtils"; public static final int deleteAudioInFolderFromMediaProvider(Context ctxt, File folder) { if (folder == null) return 0;/*from ww w .java 2s.c o m*/ ContentResolver cr = ctxt.getContentResolver(); // audio int count = 0; Cursor audioCursor = null; try { String select = Audio.Media.DATA + " like ? escape '!'"; String[] selectArgs = { escapePath(folder.getAbsolutePath()) }; String[] projection = { Audio.AudioColumns._ID }; audioCursor = cr.query(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, select, selectArgs, null); if (audioCursor.getCount() > 0) { audioCursor.moveToFirst(); List<Uri> audioToDelete = new ArrayList<Uri>(); do { String id = audioCursor.getString(audioCursor.getColumnIndex(Audio.AudioColumns._ID)); audioToDelete.add(Uri.withAppendedPath(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id)); } while (audioCursor.moveToNext()); for (Uri uri : audioToDelete) { Log.i(t, "attempting to delete: " + uri); count += cr.delete(uri, null, null); } } } catch (Exception e) { Log.e(t, e.toString()); } finally { if (audioCursor != null) { audioCursor.close(); } } return count; } private static String escapePath(String path) { String ep = path; ep = ep.replaceAll("\\!", "!!"); ep = ep.replaceAll("_", "!_"); ep = ep.replaceAll("%", "!%"); return ep; } }