Android Question Possible to request RuntimePermissions from within a class, and get the results in same class?

Sandman

Expert
Licensed User
I'm working on an existing, working project. (Using B4XPages, if that matter.)

In that work I'm moving some things into classes. A sub that request RuntimePermissions also made its way into a class, because it made sense. However, the result from the request end up in B4XPage_PermissionResult, and not in the actual class as I expected.

So I started wondering if it's even possible to request permissions from within classes, and get the results directly back into it? I couldn't find anything on the forum about it.

(I do realize that I could accept the result in B4XPage_PermissionResult and send it back into the waiting class, but I thought I'd ask the forum if there was a cleaner way of doing this first.)
 

AnandGupta

Well-Known Member
Licensed User
Longtime User
So I started wondering if it's even possible to request permissions from within classes, and get the results directly back into it? I couldn't find anything on the forum about it.
Yes.

In Calendar sample we request permission in the same page where required. Page means class, I take here.

Regards,

Anand
 
Upvote 0

Sandman

Expert
Licensed User
Well, if you do it directly from within a B4XPage, it's not really the same thing. B4XPages have this code in Main to send the result into the correct page:
B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub

Which makes me think that if I request it from a class, it won't work, as there's nothing sending it from the B4XPage into the class. I hope to be wrong, hence this thread.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I don't know if it will be useful / sufficient for you...

Delegate it you too:

B4XMainPage
B4X:
Private Sub B4XPage_PermissionResult (Permission As String, Result As Boolean)
    YourObject.PermissioneResult(Permission, Result)
End Sub
 
Upvote 0

Sandman

Expert
Licensed User
Yeah, that's exactly what I was thinking, I just wanted to see if I was missing something that made this unnecessary. Thanks.
 
Upvote 0
Top