列出所有的Android设备一个文件类型的? [英] List all of one file type on Android device?
本文介绍了列出所有的Android设备一个文件类型的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我要找回对内部和外部存储的所有.mp3文件的列表。我也想了路径参考每个.MP3文件(字符串
)(它们存储在一个列表
?)我怎么能这样做?这是一个相对昂贵的操作?如果是的话,它应该被放在一个线程同时运行,present与加载用户 ProgressDialog
?
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 reference (store them in a List
?) How could I do this? 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
?
推荐答案
请找到以下的功能。它会得到所有存储在外部和内部存储器中的MP3文件。
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();
}
}
这篇关于列出所有的Android设备一个文件类型的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文