2

I am trying to create a simple music player app, but my problem is that i am unable to access my Music folder on the internal storage:

File musicFolder = new File(Environment.getExternalStorageDirectory().getPath()+"/Music");
    if(musicFolder.isDirectory()){
        for(File f : musicFolder.listFiles()){

It works till musicFolder.listFiles() which return null. The path it is trying to access is /storage/emulated/0/Music

In the manifest of my app i declared:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Also the canRead() function of musicFolder returns false?

Does anybody know what i am doing wrong?

Edit:

I now get the music files via MediaStore... that works! But playback using MediaPlayer still tells me: Permission Denied when i try to open a music file. I verified i have READ_EXTERNAL_STORAGE permission at runtime.

  • adding in permissions to the manifest might not be enough, depending on the type of permission, look [here](https://stackoverflow.com/questions/43148879/how-to-get-read-external-storage-permissions) for a question regarding runtime permissions – a_local_nobody Feb 26 '20 at 12:41
  • 1
    You are using files for this purpose; media players usually query the `MediaStore`. And, my guess is that you did not use `checkSelfPermission()` and `requestPermissions()` to request `READ_EXTERNAL_STORAGE` at runtime, in addition to your manifest entry. – CommonsWare Feb 26 '20 at 12:43
  • i checked now the permissions at runtime and they are granted also on my phone i can verify that my app has the READ_EXTERNAL_STORAGE permission but still. I can not read the Music folder :( Can read is still false. – user1531730 Feb 26 '20 at 13:30
  • Indeed. On Android Q that will not go. And you should use `musicFolder.exists()` too. – blackapps Feb 26 '20 at 13:34

0 Answers0