This code can be used in offline songs/videos player, files management, image gallery ...
Cursor songcursor;
int song_column_index;
int songCount;
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.TITLE,
MediaStore.Video.Media.SIZE,
MediaStore.Video.Media.ARTIST,
MediaStore.Video.Media.ALBUM,
MediaStore.Audio.Media.ALBUM_ID};
songcursor = parentFragment.getActivity().managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj,
MediaStore.Audio.Media.DATA + " like ?",
new String[] {"%mp3"},
null);
try {
songCount = songcursor.getCount();
} catch (Exception e) {
return;
}
if (songCount > 0) {
for (int i=0; i<songCount; i++) {
// Your code here, for processing the result
}
}
}