Fetch Audio/MP3 files from specific folder of device or fetch all files
First, add the following permissions to the manifest of your project in order to enable device storage access:
Then, create the file AudioModel.class and put the following model class into it in order to allow getting and setting list items:
Next, use the following method to read all MP3 files from a folder of your device or to read all files of your device:
The code above will return a list of all MP3 files with the music's name, path, artist, and album. For more details please refer to the Media.Store.Audio documentation.
In order to read files of a specific folder, use the following query (you need to replace the folder name):
If you want to retrieve all files from your device, then use the following query:
Note: Don't forget to enable storage access permissions.
Now, all you have to do is to call the method above in order to get the MP3 files:
Example with Activity
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0