'how to get all audio files from internal and external storage in android studio
How can I access all audio files from my storage internal as well as external in android studio and how can I get recent audio files on top of my recyclerview?
public ArrayList<ModelClass> getData() {
ModelClass f;
String targetpath = Environment.getExternalStorageDirectory().getPath() + "/" ;
File targetdir = new File(targetpath);
files = targetdir.listFiles();
if (files.length != 0) {
for (int i = files.length -1 ; i > -1; i--) {
File file = files[i];
f = new ModelClass();
f.setUri(Uri.fromFile(file));
f.setPath(files[i].getAbsolutePath());
f.setDate((file.lastModified()));
f.setFilename(file.getName());
if (!f.getUri().toString().endsWith(".nomedia")) {
fileslist.add(f);
}
}
} else {
Toast.makeText(this, "Make dummy call", Toast.LENGTH_SHORT).show();
dummyCallAlert();
}
return fileslist;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
