字符串「外部」的作品作爲MediaStore.Audio.Playlists.Members.getContentUri(volume, playlistId)
體積這項活動將打印在Android的歌曲,播放列表,以及它們的內容。
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
public class PlaylistActivity extends Activity {
private final String [] STAR= {"*"};
private final String TAG= "list";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
Log.i(TAG, "All the titles");
Uri allaudio_uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor ca= managedQuery(allaudio_uri, STAR, null,null,null);
for(ca.moveToFirst(); !ca.isAfterLast(); ca.moveToNext()){
if(ca.isFirst()){ // print all the fields of the first song
for(int k= 0; k<ca.getColumnCount(); k++)
Log.i(TAG, " "+ca.getColumnName(k)+"="+ca.getString(k));
}else{ // but just the titles of the res
Log.i(TAG, ca.getString(ca.getColumnIndex("title")));
}
}
Log.i(TAG, "--------------------------");
Log.i(TAG, "All the playlists");
Uri playlist_uri= MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
Cursor cursor= managedQuery(playlist_uri, STAR, null,null,null);
cursor.moveToFirst();
for(int r= 0; r<cursor.getCount(); r++, cursor.moveToNext()){
Log.i(TAG, "-----");
Log.i(TAG, "Playlist " + cursor.getString(cursor.getColumnIndex("name")));
for(int k= 0; k<cursor.getColumnCount(); k++)
Log.i(TAG, cursor.getColumnName(k)+"="+cursor.getString(k));
// the members of this playlist
int id= cursor.getInt(0);
Uri membersUri = MediaStore.Audio.Playlists.Members.getContentUri("external", id);
Cursor membersCursor = managedQuery(membersUri, STAR, null, null, null);
membersCursor.moveToFirst();
for(int s= 0; s<membersCursor.getCount(); s++, membersCursor.moveToNext())
Log.i(TAG, " "+membersCursor.getString(membersCursor.getColumnIndex("title")));
membersCursor.close();
}
cursor.close();
}
}
我縮小了東西 - 我相信「外部」是我正在尋找的論點。我認爲這是因爲我可以使用任何假的字符串,並獲得相同的空遊標,但與外部的URI看起來是正確的(如上所述,它看起來像我粘貼從我使用「外部」時的版本)。 此外與「外部」,我得到不同的行爲。當調用managedQuery時,我得到一個NullPointerException,並帶有非常無用的堆棧跟蹤。 at android.content.ContentResolver.query(ContentResolver.java:149) at android.app.Activity.managedQuery(Activity.java:1499) – Brett 2010-04-14 01:59:14