How can I access playlist created by android default music app and call the music app to play it?

后端 未结 3 1715
天涯浪人
天涯浪人 2020-12-25 08:28

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

3条回答
  •  情深已故
    2020-12-25 09:14

    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

提交回复
热议问题