MediaStore Query Returns Empty Cursor

1.2k views Asked by At

I'm trying to query MediaStore for all the playlists on a device; however, the query I'm using returns empty. I've looked at solutions to this issue but they only mentioned the device being mounted and I restarted my device unplugged and the issue wasn't fixed. Any help with my issue would be greatly appreciated.

private void getPlaylists(){
    Cursor cursor = null;

    String[] projection1 = {
           MediaStore.Audio.Playlists._ID,
           MediaStore.Audio.Playlists.NAME
        };

        cursor = getContentResolver().query(
           MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
           projection1,
           null,
           null,
           null);

        Toast.makeText(this, cursor.getCount() + "", Toast.LENGTH_LONG).show();
  }

Thank you :)

1

There are 1 answers

0
Theo On

The only difference between your code and mine is the use of Context

 private final Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;

public Cursor getandroidPlaylistcursor(Context context) {
    ContentResolver resolver = context.getContentResolver();
    final String id = MediaStore.Audio.Playlists._ID;
    final String name = MediaStore.Audio.Playlists.NAME;
    final String[] columns = { id, name };
    return  resolver.query(uri, columns, null, null,name + " ASC");
}