java – 列出Android设备上的所有文件类型?

例如,我想检索内部和外部存储上的所有.mp3文件的列表.我还想要每个.mp3文件的路径(String)作为参考(将它们存储在List中?)我怎么能这样做?这是一个相对昂贵的操作吗?如果是这样,它是否应该放在一个线程上并且在运行时,向用户显示“正在加载”ProgressDialog?

解决方法:

请找到下面的功能.它将获得存储在外部和内部存储器中的所有mp3文件.

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();
    }
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...