在我的Android应用程序中,我想在用户长按特定歌曲时从播放列表中删除歌曲。为此,我使用Contentresolver.delete()
方法,但它不起作用。既不会抛出错误也不会删除数据?我在这里发布我的代码。请告诉我它为什么不起作用。
代码:
ContentResolver resolver = DefaultSongList.this.getContentResolver();
Uri mUri = MediaStore.Audio.Playlists.Members.getContentUri("external",playListId);
String audioId = songsList.get(pos).get("id");
resolver.delete(mUri,MediaStore.Audio.Playlists.Members.AUDIO_ID +" = "+ audioId , null);
Toast.makeText(DefaultSongList.this, "Song removed from Playlist.", Toast.LENGTH_SHORT).show();
答案 0 :(得分:2)
试试这个:
public void removePlaylistMember(Context context, long memberid,
long mplaylistid) {
try {
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
"external", mplaylistid);
String selection = MediaStore.Audio.Playlists.Members.AUDIO_ID
+ "=?";
String selectionargs[] = { String.valueOf(memberid) };
context.getContentResolver().delete(uri, selection, selectionargs);
} catch (Exception e) {
}
}