Android Question Wait for and runtime permision

victormedranop

Well-Known Member
Licensed User
Longtime User
Hi i'm trying to create an wait for function that
wait the user entry before starting the google map fragment.
but no luck.

anyone wants to share some interesting data.

thanks,

Victor
 

Brandsum

Well-Known Member
Licensed User
Assuming that you want some permission before starting some execution (As per this thread title)

Just check if you have the specific permission:
B4X:
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)

Then check if the user gives you the permission and do whatever you want:
B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION And Result = True Then
        'Start the google map fragment or whatever you want
    End If
End Sub
 
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
the issue is that the map start before autorize fine location.

i need to delay this sub, waiting to aprove the permisions.

B4X:
sub MapFragment_google_Ready

something like this (this dows not work)

B4X:
Sub permisions
    Dim rw As RuntimePermissions
    rw.CheckAndRequest(rw.PERMISSION_ACCESS_FINE_LOCATION)
   
    Wait For (rw) Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION Then
        Log("fine location")
       
    End If
   
End Sub

Victor
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Did you try something like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)   
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        MsgboxAsync("No permission granted", "")
        Return
    Else
        MapFragment_google_Ready  'call this sub
    End If
End Sub
 
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
Still Getting the same error with google map initialization.

java.lang.RuntimeException: java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION

victor
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
No need to use wait for. rp.CheckAndRequest will wait for the user interaction on its own. You have to add that permission to your manifest too.

1. Add permission to manifest
2. Ask permission on activity resume
3. On permission granted run your code from Activity_PermissionResult
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top