I have used his code before, and it has always worked.
Now, a strange thing happens:
I run the app for the first time.
Android requests permission for this app to make changes.
I grant permission for this app.
The MakeDirectory fails. No error message, it simply does not make the directory.
I run the app a second time.
Android does not ask permission (it already has permission from the first run).
The MakeDirectory works and creates the folder.
I suspect that Android asks permission when it sees this line, and when I grant permission, it executes this line before it has time to register that permission has been granted. This would explain why it fails the first time, does not request permission the second time, but then the line works on the second run of the app.
Is my understanding correct? If so (or if not), could anyone suggest a work-around (perhaps an earlier trigger and then later execution?), so that the app can create the directory the first time it runs.
WRITE permission is only requested on Android < 11. WRITE permission implicitly grants READ permission. So there is no need to request READ permission. makeDir.aia (16.0 KB)
Thanks very much all, for your suggestions. I managed to draw from all of he ideas, and went with using the TinyDB for checking if the folder exists, and, if it doesn’t, asking permission and then making if permission is granted.
Hmm? Show me the relevant blocks. I'm curious to see how that's supposed to work with TinyDB.
But you could use the File.Exists method. And tell us the Android version of your test device.