title: Android Create Playlist
body: <p>Anyone know how to add playlists to Android in code?</p>
  
  <p>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 I have to put all of the song's data in?</p>
  
  <p>I have been looking for sample code but haven't found any yet.</p>
  
  <p>EDIT:
  Found an answer here is how I do it:</p>
  
  <pre><code>  public static void addToPlaylist(ContentResolver resolver, int audioId) {
  
          String[] cols = new String[] {
                  "count(*)"
          };
          Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", YOUR_PLAYLIST_ID);
          Cursor cur = resolver.query(uri, cols, null, null, null);
          cur.moveToFirst();
          final int base = cur.getInt(0);
          cur.close();
          ContentValues values = new ContentValues();
          values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + audioId));
          values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId);
          resolver.insert(uri, values);
      }
  
     public static void removeFromPlaylist(ContentResolver resolver, int audioId) {
         Log.v("made it to add",""+audioId);
          String[] cols = new String[] {
                  "count(*)"
          };
          Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", YOUR_PLAYLIST_ID);
          Cursor cur = resolver.query(uri, cols, null, null, null);
          cur.moveToFirst();
          final int base = cur.getInt(0);
          cur.close();
          ContentValues values = new ContentValues();
  
          resolver.delete(uri, MediaStore.Audio.Playlists.Members.AUDIO_ID +" = "+audioId, null);
      }
  </code></pre>