title: Scoped Storage & MediaStore & Api 30: Can delete track from Playlist, but can't add
body: <p>I have a music player app for Android. There is a strange issue with MediaStore. I can delete or add songs to my own playlists on MediaStore (eg, created by my app). However, when I try to add a song to a playlist created by another application, it throws <code>java.lang.SecurityException</code>, but I can delete songs from the exact same playlist!</p>
  <p>I have all required permissions:</p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot;/&gt;
  </code></pre>
  <p>And my code:</p>
  <pre><code>public Uri addTrackToPlaylist(Context context, TrackLocal trackLocal, long playlist_id, int pos) {
      ContentResolver resolver = context.getContentResolver();
      Uri newuri = MediaStore.Audio.Playlists.Members.getContentUri(getVolume(), playlist_id);
      ContentValues values = new ContentValues();
      values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, 0);
      values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, trackLocal.dbid);
      Uri uri = resolver.insert(newuri, values);
      return uri;
  }
  
  public int deletePlaylistTrack(Context context, long playlistId, TrackLocal trackLocal) {
      ContentResolver resolver = context.getContentResolver();
      Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(getVolume(), playlistId);
      String filter = MediaStore.Audio.Playlists.Members.AUDIO_ID + &quot; = &quot; + trackLocal.dbid;
      return resolver.delete(uri, filter, null);
  }
  
  private String getVolume() {
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.Q) {
          return MediaStore.VOLUME_EXTERNAL;
      } else {
          return &quot;external&quot;;
      }
  }
  </code></pre>
  <p>Does anyone have an idea at least how to workaround this?</p>
  <p>Thanks.</p>