This is the code working for years up to Android 12 since Android 8.
B4X:
gRp.CheckAndRequest(gRp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
Dim outs As OutputStream = File.OpenOutput(gRp.GetSafeDirDefaultExternal("") , gs_filename, False)
...
outs.Close
Else
ToastMessageShow("Failed to create file", False)
End If
This is an example of how some apps like file managers, antivirus and other apps that depends on access to DirRootExternal to create folders, create files and read files from the Root of the device. NOTE: This cannot be published to the Google Play store unless your apps CORE functionality...
This is an example of how some apps like file managers, antivirus and other apps that depends on access to DirRootExternal to create folders, create files and read files from the Root of the device. NOTE: This cannot be published to the Google Play store unless your apps CORE functionality...
Thanks. Tried your example which works but failed when I use GetSafeDirDefaultExternal.
I further debug then found the following
B4X:
gRp.CheckAndRequest(gRp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
...
The problem is CheckAndRequest failed to return permissionResult (in Android 13 and 14, but no issue in Android 9-12), hence timeout then prompt "failed" message.
If I comment the CheckAndRequest and Wait For Acitivity_PermissionResult, and and comment "If Result then", I can create file in GetSafeDirDefaultExternal folder. i.e. my app has got access to create new files.
Then question is why CheckAndRequest(gRp.PERMISSION_WRITE_EXTERNAL_STORAGE) failed?
Thank you Sagenut. This works (I thought it was workaround ).
Also notice there was new b4x deployed by Erel. Download and use new ide to compile, solved other part of my problems. i.e. next time when Erel release a version, should download and recompile and test app asap.