我使用以下代码创建了一个播放列表
ContentValues cv = new ContentValues();
cv.put(MediaStore.Audio.Playlists.NAME, "123456");
//Uri uri = getContentResolver().insert(MediaStore.Audio.Playlists.getContentUri("external"), cv);
Uri uri = getContentResolver().insert(MediaStore.Audio.Playlists.INTERNAL_CONTENT_URI, cv);
if (uri != null)
{
Toast.makeText(getApplicationContext(),uri.toString(),
Toast.LENGTH_LONG).show();
}
每次运行代码时,我都会在内容中创建播放列表的详细信息:// media / internal / audio / playlists,然后显示播放列表的ID
现在此活动用于显示手机中的播放列表
public class playlist extends ListActivity {
//define source of MediaStore.Images.Media, internal or external storage
Uri sourceUri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
//Uri sourceUri = MediaStore.Audio.Playlists.INTERNAL_CONTENT_URI;
SimpleCursorAdapter mySimpleCursorAdapter;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] from = {MediaStore.Audio.Playlists.NAME};
int[] to = {android.R.id.text1};
CursorLoader cursorLoader = new CursorLoader(
this,
sourceUri,
null,
null,
null,
MediaStore.Audio.Playlists.NAME);
Cursor cursor = cursorLoader.loadInBackground();
mySimpleCursorAdapter = new SimpleCursorAdapter(
this,
android.R.layout.simple_list_item_1,
cursor,
from,
to,
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
setListAdapter(mySimpleCursorAdapter);
getListView().setOnItemClickListener(myOnItemClickListener);
getListView().setOnItemLongClickListener (myOnItemLongClickListener);
getListView().setLongClickable(true);
}
OnItemClickListener myOnItemClickListener
= new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Cursor cursor = mySimpleCursorAdapter.getCursor();
cursor.moveToPosition(position);
String _id = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Playlists._ID));
Uri selUri = Uri.withAppendedPath(sourceUri, _id);
Intent i=new Intent(playlist.this,getsongfromplaylist.class);
i.putExtra("id", _id);
playlist.this.startActivity(i);
}
};
OnItemLongClickListener myOnItemLongClickListener
= new OnItemLongClickListener(){
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
Cursor cursor = mySimpleCursorAdapter.getCursor();
cursor.moveToPosition(position);
String _id = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Playlists._ID));
Uri selUri = Uri.withAppendedPath(sourceUri, _id);
Intent i=new Intent(playlist.this,popuplist.class);
i.putExtra("id", _id);
playlist.this.startActivity(i);
return true;
}
};
在此活动中,所有播放列表都显示在手机中可用,但新创建的播放列表未显示
对于我手机预装的默认音乐播放器也会出现这种情况
现在我知道问题是
带
Uri uri = getContentResolver().insert(MediaStore.Audio.Playlists.INTERNAL_CONTENT_URI, cv);
在createplaylist代码中
和
Uri sourceUri = MediaStore.Audio.Playlists.INTERNAL_CONTENT_URI;
如果我更改了活动崩溃的相应代码中的internal or external content uri
所以我的问题会
1)如何使用external content uri
2)如何使用两者显示播放列表和所有其他播放列表
external content uri
和internal content uri