List all of one file type on Android device?

前端 未结 1 2006
暖寄归人
暖寄归人 2021-01-07 00:51

For example, I want to retrieve a list of all .mp3 files on the internal AND external storage. I would also like the path (String) of each .mp3 file for referen

相关标签:
1条回答
  • 2021-01-07 01:05

    Please find the function below . It will get all the mp3 files stored in external and Internal memory .

    public void getAllSongs() {
    
        Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
    
        cursor = managedQuery(allsongsuri, STAR, selection, null, null);
    
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                do {
                    song_name = cursor
                            .getString(cursor
                                    .getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
                    int song_id = cursor.getInt(cursor
                            .getColumnIndex(MediaStore.Audio.Media._ID));
    
                    String fullpath = cursor.getString(cursor
                            .getColumnIndex(MediaStore.Audio.Media.DATA));
                    fullsongpath.add(fullpath);
    
                    album_name = cursor.getString(cursor
                            .getColumnIndex(MediaStore.Audio.Media.ALBUM));
                    int album_id = cursor.getInt(cursor
                            .getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
    
                    artist_name = cursor.getString(cursor
                            .getColumnIndex(MediaStore.Audio.Media.ARTIST));
                    int artist_id = cursor.getInt(cursor
                            .getColumnIndex(MediaStore.Audio.Media.ARTIST_ID));
    
    
                } while (cursor.moveToNext());
    
            }
            cursor.close();
            db.closeDatabase();
        }
    }
    
    0 讨论(0)
提交回复
热议问题