1

I am using this code to get all music files in the SD card, but when i delete a file it still shows it, and if i add a new file to the SD card it doesnt show it.

This is to get all music files

private String[] getMusic() {
    String[] proj = { MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.TITLE, };

    mCursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            proj, null, null, "LOWER(" + MediaStore.Audio.Media.TITLE
                    + ") ASC");

    int count = mCursor.getCount();

    String[] songs = new String[count];
    int i = 0;
    if (mCursor.moveToFirst()) {
        do {
            songs[i] = mCursor.getString(2);
            i++;
        } while (mCursor.moveToNext());
    }

    return songs;
}

And this to list it in a ListView

mMusicList = getMusic();


    rowItems = new ArrayList<rowItem>();
    for (int i = 0; i < mMusicList.length; i++) {
        rowItem item = new rowItem(mMusicList[i]);
        rowItems.add(item);
    }

Thanks in advance

Paul
  • 15
  • 3
  • I think that you want to take a look at [this stackOverflow question](http://stackoverflow.com/questions/3300137/how-can-i-refresh-mediastore-on-android). He is talking about playlists but I think this issue might be the same -- getting the truth from the database. – hack_on Feb 27 '13 at 09:43

0 Answers0