MakeDirectory Fails on First run of app, works on second

I have a command to use File1.MakeDirectory (See attached)

I have used his code before, and it has always worked.

Now, a strange thing happens:

  1. I run the app for the first time.
  2. Android requests permission for this app to make changes.
  3. I grant permission for this app.
  4. The MakeDirectory fails. No error message, it simply does not make the directory.
  5. I run the app a second time.
  6. Android does not ask permission (it already has permission from the first run).
  7. 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.

Thanks

Ken

What permission are you requesting ?

1 Like

My code is in a standard screen1.initialize handler, and I just wish to create a folder on the phone, for read/write permissions.

Don't use the MakeDirectory block in that Initialize event. Use it after the permission has been granted in the PermissionGranted event

Please show us a screenshot of your complete Screen1.Inizialize event

Taifun

1 Like

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)

1 Like

Or perhaps this (no extension required)

Yes, but if the user revokes the storage permission, TinyDB will no longer function correctly.

1 Like

To work on all Android version I need to add another block: