Android Question fused gps permissions

Tomas Petrus

Active Member
Licensed User
Longtime User
Hi Guys, I already have readed all possible tutorials that are here
and implemented fusedLocation provider trough the starter service.

But I want to wait in Activity_Resume until permissions are confirmed (or declined)

<code>
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
' HERE I WANT TO WAIT
Wait For Starter.rp_PermissionResult (Permission As String, Result As Boolean)
If Result = True Then
ToastMessageShow("Do sometning", True)
End If
</code>

But it doesnt work..

I was following this example:

Sub ReadFile (f As String)
rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission...", True)
Else
Log(File.ReadString(File.DirRootExternal, f))
End If
End Sub

Just trying to call PermissionResult from starter not from activity, because of how the fused location was implemented.

Result is I cannot even compile "cannot cast type .....to number"
thanks for advices.
 

Tomas Petrus

Active Member
Licensed User
Longtime User
Erel thx, but I dont understand

I was using your GPS tutorial and this is your code:

B4X:
Sub Activity_Resume
   If Starter.GPS1.GPSEnabled = False Then
     ToastMessageShow("Please enable the GPS device.", True)
     StartActivity(Starter.GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
   Else
     Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
   End If
End Sub

I have similar code in my Activity resume I just need to wait after

Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I just need to wait after
where is the problem?
B4X:
    starter.rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!", True)
    End If
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
If I use your code

B4X:
Starter.rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result = True Then
            ToastMessageShow("Do sometning", True)
        End If

then IDE make the line with wait RED and said current declaration doesnt match the previous one
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
I need to wait after CheckAndRequest because

B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = Starter.rp.PERMISSION_ACCESS_FINE_LOCATION Then
        If Result Then CallSub(Starter,"StartGPS")
     
        If Starter.LastLocation.IsInitialized Then
            UpdateUI
        End If
    End If
end sub

first load without permissions UPDATEUI will not run because IF is geting hit imidiately after request perm, it doesnt make any crashes but application first load without permissions is loaded with no GPS stuff that I need. After that everything work fine in the app. second starts with permissions already sets work fine too.

Maybe I am looking on it from wrong point of view ? : )

[edit]
The call in the Permission result is maybe pointless, because I am calling it again in jobdone and that one is what is getting hit without wait for perm.
 
Last edited:
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
so I wanted to run
B4X:
Starter.rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)

'WAIT 

If Starter.LastLocation.IsInitialized Then
            UpdateUI
End If

to fix that.
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
thx
I understand the meaning of the answer, but that doesnt mean that I understand what to do with that. Those wait calls are new to me..

B4X:
Starter.rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
'        Msgbox("sss",Activity_PermissionResult (Permission As String, Result As Boolean))
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        Dim res As Int 'WTF ? : )
        If Result = True Then
            ToastMessageShow("Do sometning", True)
        End If

I am lost..
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
got it so far

B4X:
Dim res As Int 
Wait For res = Activity_PermissionResult (Permission As String, Result As Boolean)
Msgbox("res", res)

wanted to se the INT in res but msgbox doesnt get hit...
so I asume that I am trying it wrong way?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Dim res As Int
Wait For res = Activity_PermissionResult (Permission As String, Result As Boolean)
Msgbox("res", res)
What the hell are you trying here?
Change the line
B4X:
dim Result = msgbox2(...)
to
B4X:
dim res as int = msgbox2(...)

You then can use
B4X:
starter.rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!", True)
    End If
 
Upvote 0
Top