I'm developing an Android App for Android 8.0 where I need to open/read and delete files from the external storage / SD card.
My problem is, that File file[] = directory.listFiles()
returns NULL, but there is a file in the directory.
Here is the debugger view from my app:
As you can see, I'm getting the filepath as an URI through an Intent request (variable resource
). Currently, the folder Test
on the SD card is selected.
Then I want to get all the files in this directory, but the function listFiles()
returns always NULL! But there is 1 image in the folder:
Interestingly, this code works on Android 4.4, 5.0, 6.0 and 7.0 but not on Android 8!
The permissions are set in Manifest.xml and are requested/checked on each startup:
Note: Android only shows 1 permission request when starting the app, but shouldn't it request 2 permissions?
I hope someone of you can help me solve the problem.
Best regards, Michael