Bug? Bug with runtimepermissions in android.jar (android 28)

Status
Not open for further replies.

hatzisn

Well-Known Member
Licensed User
Longtime User
Hi everyone,

I discovered something going wrong in runtimepermissions when reverting to android 28 (android.jar).

I have two runtimepermissions "check and request" for Location in activity create sub and following these two I call a sub to locate position with GPS library and then if GPS location was not successful I locate with esLocation2 with network.

Here is the code in Activity_Create:

B4X:
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
rp.CheckAndRequest(rp.PERMISSION_ACCESS_COARSE_LOCATION)
LocatePosition

When I first install the app (Release obfuscated) it does not show the check for permission dialog and shows an error saying that the user has not permitted the use of its location when getting in the LocatePosition sub. If I start it with debug and set a breakpoint in the first runtime permission request then the permission dialog shows and by authorizing the permission everything works perfect.

My B4A version is 7.80.

Any suggestions?
Thanks in advance
 

MarkusR

Well-Known Member
Licensed User
Longtime User
this CheckAndRequest will create an Event in Activity_...
u can use Wait For to fetch this direct after your call CheckAndRequest

@Erel
i would like to see this syntax (a Wait For inside this CheckAndRequest)
if rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)=true then
 

hatzisn

Well-Known Member
Licensed User
Longtime User
Thank you both for replying...
I created a sample project to test it and here is my code:

B4X:
#Region  Project Attributes

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim rp As RuntimePermissions
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Button1 As Button
    Dim g As GPS
   
    Dim r As ESLocation2
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
   
    Dim bOk1 As Boolean
    Dim bOk2 As Boolean
   
   
    g.Initialize("gps")
    r.Initialize("es")
   
    Activity.LoadLayout("1")
   
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    wait for Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION Then
        bOk1 = Result  
    End If

    rp.CheckAndRequest(rp.PERMISSION_ACCESS_COARSE_LOCATION)
    wait for Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = rp.PERMISSION_ACCESS_COARSE_LOCATION Then
        bOk2 = Result
    End If
   
    If bOk1 And bOk2 Then
        LocatePosition
    Else
        ToastMessageShow("The user did not permit the use of its location.", True)
    End If
End Sub

Sub LocatePosition
    Msgbox("Locating position.", "Title")
    g.Start(5000, 50)
    Msgbox("Started.", "Title")
    g.Stop
    Msgbox("Stopped.", "Title")
End Sub

Sub es_Locationchanged (Longitude As Double, Latitude As Double, Altitude As Double, Accuracy As Float, Bearing As Float, Provider As String, Speed As Float, Time As Long)
   
End Sub

Sub gps_LocationChanged (Location1 As Location)
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

What I get now is that it gets directly in the LocatePosition sub (bOk1 = true AND bOk2 = true - no pemission dialogs are shown). The previous app "B4A Example" with the packet "b4a.example" that I had installed and uninstalled it to install this app had requested this two permissions. Does it keep them even after uninstallation? Or is it a bug?

Any suggestions are highly appreciated... For the record the app does not break now...
 

MarkusR

Well-Known Member
Licensed User
Longtime User
i would not call LocatePosition in the Create sub.
u should also check Location1.Accuracy in meters and Location1.AccuracyValid
it take awhile after enabling gps until u get correct position data.
u should use your own package name for each app.
see permission manager app, there u should remove given permissions.
test your app behaving also if the user not give permissions.
 

hatzisn

Well-Known Member
Licensed User
Longtime User
Thanks a lot MarkusR
 

hatzisn

Well-Known Member
Licensed User
Longtime User
Sorry MarkusR, why wouldn't you call the LocatePosition in the Activity_Create sub?
How would you call it?
 
Status
Not open for further replies.
Top