如何解决如何使用文件扩展名例如:“.mp3”或“.m4a”或“.xyz”从外部存储中列出自定义文件 - Android Studio
我想从我的 android 设备检索文件并在列表视图或回收站视图中列出它们。我需要使用文件扩展名来执行此操作,以便我还可以检索具有自己文件扩展名的定制文件,例如:“.xyz”。 这是我到目前为止所做的
public static ArrayList<MyFiles>getAllFiles(Context context){
ArrayList<MyFiles>tempList = new ArrayList<>();
Uri uri = MediaStore.Files.getContentUri("external");
Cursor cursor = context.getContentResolver().query(uri,null,null);
if (cursor!=null && cursor.moveToFirst()){
while (cursor.moveToNext()){
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DISPLAY_NAME));
String ext = title.substring(title.lastIndexOf(".")+1);
if (ext.equals("mp3")||ext.equals("m4a")||ext.equals("xyz")){
// check...
Log.e("path: "+path,"Name: "+title);
//adding the path and title to my Model Class
MyFiles myFiles = new MyFiles(path,title);
tempList.add(myFiles);
}
}
}
return tempList;
}
此方法成功返回带有“.mp3”和“.m4a”扩展名的文件列表,但未显示扩展名为“.xyz”的文件。我错过了什么,或者有更好的方法吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。