Android Question CheckAndRequest permissions always false

nibbo

Active Member
Licensed User
Longtime User
Hi All

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?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
RuntimePermissions.CheckAndRequest is not displaying a dialog and always returns false!
What is you manifest-editor code?
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
1. Code with Msgbox = broken code. This is the first thing that should be fixed.
2. Do you see this permission under Logs - List Permissions ?

Thanks Erel

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..
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Appreciate what you are saying about MsgBox but I prefer it, it does what I need it to do.
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.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Appreciate what you are saying about MsgBox but I prefer it, it does what I need it to do.
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 :(
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
But what do you do when you have 600+ MsgBox's in 70 modules and no time to revisit and revise each occurance? :(
I have faced similar situation in different programming language and I have solved it as below,
  1. search & replace all 'msgbox' with 'gMsgBox' (say)
  2. create gMsgbox sub
  3. uses latest xui.msgbox.. with wait for in it (say)
  4. TADA !
Hope it gives some idea if not helped.
P.S. search replace using some editor or program to do the job across all codes

Regards,

Anand
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
uses latest xui.msgbox.. with wait for in it (say)!

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.
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
I think my logic is making 'gMsgbox' as modal, which is old 'Msgbox'

You may check it in small project and confirm. If it does or not.

Regards,

Anand
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
You may check it in small project and confirm. If it does or not.

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.
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
It is XUI.MsgBoxAsync , I just wrote quickly. But as agraham said and you found out, it may not be possible.

Have to think of a different way.

Regards,

Anand
 
Upvote 0

udg

Expert
Licensed User
Longtime User
I am a bit late, but.. can't you automatically parse your code substituting MsgBox (<message>, <title>) with
B4X:
Wait For (xui.MsgboxAsync(<message>, <title>)) Msgbox_Result (Result As Int)
?
I mean, writing a simple B4J tool that loops on every source file in your dir while applying the substitution..
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
B4X:
Wait For (xui.MsgboxAsync(<message>, <title>)) Msgbox_Result (Result As Int)
?

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.
 
Upvote 0

Similar Threads

Top