I am trying to get all the media files from the device Internal Storage. I used MediaStore to retrieve it but it return only one song.
Please I want it to return all song in internal Storage, but it return only one song, please help me to check where the problem is.
Here is my code main activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView audioView = (ListView) findViewById(R.id.songView);
ArrayList<String> audioList = new ArrayList<>();
String[] proj = { MediaStore.Audio.Media._ID,MediaStore.Audio.Media.DISPLAY_NAME };// Can include more data for more details and check it.
Cursor audioCursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
if(audioCursor != null){
if(audioCursor.moveToFirst()){
do{
int audioIndex = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
audioList.add(audioCursor.getString(audioIndex));
}while(audioCursor.moveToNext());
}
}
audioCursor.close();
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,android.R.id.text1, audioList);
audioView.setAdapter(adapter);
}
}`
2
Answers
Wow it now work, the problem was located in Cursor audioCursor = getContentResolver().query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, proj, null, null, null); I changed getContentResolver query to INTERNAL_CONTENT_URI coz I do not have sdcard on my device.
Thank you all for your support.
You can try it like this.
1st add these two permission manifests and give programmatically
For Android 13 or higher you need only this one permission for audio
And Get All Audios Like this
I get All Audios See below