title: Dynamic query with content resolver using 'IN' clause
body: <p>I am trying to get a list of songs that matches a list of media Id's using content Resolver.</p>
  <p>I have followed this answer <a href="https://stackoverflow.com/a/32684127/15985008">Here</a> to query items dynamically with content resolver</p>
  <p>I am trying to query a list of songs that matches a list of id's passed.</p>
  <p>E.G</p>
  <p><em>SELECT FROM MUSIC DATABASE WHERE _ID = {12, 13, 14, 15, 16}</em> -&lt;&lt; <em>This is dynamic, not fixed. could be empty or could be more.</em></p>
  <p>So, I want this to return a list of song attributes with those id.</p>
  <p><strong>MusicDatabase</strong></p>
  <pre><code>fun getSongsInPlaylist(songIds: List&lt;Long&gt;): List&lt;Songs&gt; {
  
      val selection = MediaStore.Audio.Media._ID + &quot; IN (&quot; + TextUtils.join(
          &quot;,&quot;, Collections.nCopies(songIds.size, &quot;?&quot;))+&quot;)&quot;
      val songList = mutableListOf&lt;Songs&gt;()
      val collection = Utility.sdk29AndUp {
          MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL)
      } ?:  MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
  
      for (i in songIds.indices) selectionArgs!![i] = songIds[i]
  
  
      //Get songs from provider
      context.contentResolver.query(
          collection,
          projection,
          selection,
          arrayOf(selectionArgs.toString()),
          MediaStore.Audio.Media.DEFAULT_SORT_ORDER //Sort in alphabetical order based on display name.
      ).use { cursor -&gt;
          if (cursor?.moveToFirst() == true) {
  
              do {
       }
  </code></pre>
  <p><strong>MusicViewModel</strong></p>
  <pre><code> fun doGetAllSongsInPlaylist(songIds: List&lt;Long&gt;){
  
      val permissionGranted = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
      if (permissionGranted){
          viewModelScope.launch {
              val songs = songsInPlaylistDatabase.getSongsInPlaylist(songIds)
              _songsInPlaylist.value = Resource.success(songs)
          }
      }
  }
  </code></pre>
  <p><strong>Fragment</strong></p>
  <pre><code> args.playlist.playlistId?.let { roomPlaylistViewModel.doGetAllSongsInPlaylist(it) }
      roomPlaylistViewModel.songsInPlaylist.observe(viewLifecycleOwner){ songs-&gt;
          for (songId in songs){
              songId.songId.let { it1 -&gt;
                  if (it1 != null) {
                      songIdArray.add(it1)....//I am getting songId's and saving in an array
                  }
              }
          }
  
     
    viewLifecycleOwner.lifecycleScope.launch {
              viewLifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED){
                  
              playlistViewModel.doGetAllSongsInPlaylist(songIdArray)...//I am passing the song Id's stored in array here
             
                  playlistViewModel.songsInPlaylist.collect{ result -&gt;
                      when(result.status) {
                          Status.SUCCESS -&gt; {
                              result.data?.let { songs -&gt;
                                  Log.e(&quot;lisx&quot;, songs.toString())
                              }
                          }
                          Status.ERROR -&gt; Unit
                          Status.LOADING -&gt; Unit
                      }
                  }
              }
  </code></pre>
  <p>I am getting an error:</p>
  <p><strong>java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range.  The statement has 0 parameters</strong></p>