RuntimePermissions.CheckAndRequest is not displaying a dialog and always returns false!
B4X:
If phone.SdkVersion >= 24 Then
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, rpResult As Boolean)
If Not(rpResult) Then
'no permission
Msgbox("Unable to access device storage.", "Warning")
Return False
End If
End If
Testing on a device with SDK version 25.
I thought that this should display a dialogue the first time it is called for an app and then retain the users choice for subsequent runs but I never saw a dialogue.
Pretty sure it used to work?
Appreciate what you are saying about MsgBox but I prefer it, it does what I need it to do.
The permission is not listed in the logs, does this mean it will only pop up the dialog if I actually need it?
I am planning to use external storage later in this app but I was just testing what I have done so far.
When I implement the new bit that requires the permission will it suddenly start requesting it? Clever..
As the one who wrote it I can safely say that it is a mistake. Anyway, only permissions listed in the generated manifest can be requested at runtime. You can add the permission now with AddPermission in the manifest editor.
Definitely a mistake nowadays. It worked fine for early Android but later versions have cocked-up improved message loop handling so much that modal MsgBox is potentially unreliable and can cause exceptions in your app. I've been bitten by it
I thought that but if the MsgBox is a few subs deep you have to make them all resumable and wait for each one otherwise the first wait will pass control back to the last calling sub without a wait. I am sure it will be fine in most cases but its a matter of checking each MsgBox and seeing what will happen if the app continues without waiting higher up.
I may be doing it wrong; I dont see a XUI.MsgBox only MsgBoxAsync .
I called SubOne from Acticity_Create, SubOne then called SubTwo which had a XUI.MsgBoxAsync with a wait.
As soon as the wait is hit in SubTwo, SubOne carried on and when complete passes back to Activity_Create so as I suspected, I would have to wait for each sub in turn.
Thanks udg, but as I say, this will only work if you don't care if the program flow continues without waiting for the user to click OK.
Waits in nested subs will pass control back to the the calling subs unless they are all resumable with waits.
These apps are up to 6 years old and written before the MsgBox was replaced with the Async versions so I would still have to check that allowing the code to continue executing would be OK.