Anyone know how to add playlists to Android in code?
I kind of get that I have to insert it into the content resolver but do I have to just put the song id in or do
To answer Jaroslav Záruba comment, the code is better with the PLAY_ORDER of added track set as follows:
cur.moveToLast();
final int base = cur.getInt(cur.getColumnIndex(Playlists.Members.PLAY_ORDER));
cur.close();
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER,
Integer.valueOf(base + 1));
Two major things change : We use the last element of the playlist (cur.moveToLast()) and we add 1 to its PLAY_ORDER value to determine the new track's PLAY_ORDER. The point is to have successive tracks in the playlist.
You can also add 10 for example so that you can insert tracks before or after your new track. I also changed the way we get the id of track. Indeed we don't want to have any problem getting wrong data so we specify the column we want.