I want to receive audio files in SD card
In my application, I want to set ringtone
when I receive an incoming call ... How to open SDCARD
and receive audio files and list it. How to get URI
for the selected audio file
..
+1
kannappan
source
to share
1 answer
MediaScanner finds music for you by populating the MediaStore database. Here's some code to find music:
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);
The data field contains a descriptor that you can use with the MediaPlayer. when first crawling and indexing the media, scan it with AsyncTask, but later when intent is received, use it with the service.
+5
evilone
source
to share