[英]List all of one file type on Android device?
For example, I want to retrieve a list of all .mp3 files on the internal AND external storage. 例如,我想检索内部和外部存储上所有.mp3文件的列表。 I would also like the path ( String
) of each .mp3 file for reference (store them in a List
?) How could I do this? 我还希望每个.mp3文件的路径( String
)可供参考(将它们存储在List
?)我该怎么做? Is this a relatively expensive operation? 这是一个相对昂贵的手术吗? If so, should it be put on a thread and while that is running, present the user with a "Loading" ProgressDialog
? 如果是这样,是否应将其放在线程上并在其运行时为用户提供“正在加载” ProgressDialog
?
Please find the function below . 请在下面找到功能。 It will get all the mp3 files stored in external and Internal memory . 它将获取存储在外部和内部存储器中的所有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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.