在我的应用程序我想设置铃声
当我收到来电......如何打开 SD卡
并获得的音频文件的,并列出它。如何获得 URI
为选定音频文件
..
In my app I want to set the ringtone
when I get an incoming call... How to open the SDCARD
and get audio files and list it.. How to get the URI
for the selected audio file
..
MediaScanner发现音乐对你来说,填充MediaStore数据库。下面是一些code查找音乐的条目:
MediaScanner finds music for you, populating the MediaStore database. Here's some code to look up a music entry:
final Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
final String[] cursor_cols = {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.TITLE,
};
final String where = MediaStore.Audio.Media.IS_MUSIC + "=1";
final Cursor cursor = getContentResolver().query(uri, cursor_cols, where, null, null);
cursor.moveToNext();
final String artist = cursor.getString(_cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
final String album = cursor.getString(_cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
final String track = cursor.getString(_cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
doSomethingHere(artist, album, track);
数据字段中包含的句柄可以用的MediaPlayer使用。而这样做的媒体文件的扫描和索引的第一次,扫描,使用的AsyncTask,但后来当使用一个服务都收到一个意图。
The "data" field contains a handle you can use with MediaPlayer. while doing this media files scanning and indexing for the first time, scan it using a AsyncTask, but later when a intent is received do it using a service.