I am writing an android app, and I want to access the playlist created by android default music app.
In my app, the user should be able to browse the playlist and se
To display all the playlist created by user in default music application in Android, I am using following block of code in my Activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] proj = {"*"};
Uri tempPlaylistURI = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
// In the next line 'this' points to current Activity.
// If you want to use the same code in other java file then activity,
// then use an instance of any activity in place of 'this'.
Cursor playListCursor= this.managedQuery(tempPlaylistURI, proj, null,null,null);
if(playListCursor == null){
System.out.println("Not having any Playlist on phone --------------");
return;//don't have list on phone
}
System.gc();
String playListName = null;
System.out.println(">>>>>>> CREATING AND DISPLAYING LIST OF ALL CREATED PLAYLIST <<<<<<");
for(int i = 0; i " + i + " : " + playListName );
}
if(playListCursor != null)
playListCursor.close();
}
Don't forget to include these before using
import android.net.Uri;
import android.provider.MediaStore;
import android.database.Cursor;
This code is Tested and working fine over target = android-8