Android Question Problem with PERMISSION_ACCESS_FINE_LOCATION Or PERMISSION_ACCESS_COARSE_LOCATION

Filippo

Expert
Licensed User
Longtime User
Hi,

I have a problem with these 2 statements when I need to use SDK-31:
If you want to set targetSdKVersion to 31 then the main changes are:
- When requesting the fine location permission the user can choose to limit your app to coarse location. The code to handle it is:
B4X:
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
If Result Or rp.Check(rp.PERMISSION_ACCESS_COARSE_LOCATION) Then
 'we have location permission
End If

How should it work if the user only approves "PERMISSION_ACCESS_COARSE_LOCATION", if the BLEManager.StartScan requires the ACCESS_FINE_LOCATION permission?
I'm a little confused.

This is the code I am currently trying:
B4X:
Private Sub CheckPermission_SDK31
    If Not(Starter.rp.Check( Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)) Then
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result = False Or Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_COARSE_LOCATION) = False Then
            MsgboxAsync(Starter.language.Value("PERMISSION_ACCESS_COARSE_LOCATION"), Starter.language.Value("PermissionDenied"))
            Wait For Msgbox_Result
            Return
        End If
    End If

    For Each Permission As String In Array("android.permission.BLUETOOTH_SCAN", "android.permission.BLUETOOTH_CONNECT")
        'Log("Permission=" & Permission)
        Starter.rp.CheckAndRequest(Permission)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result = False Then
            MsgboxAsync(Starter.language.Value("PERMISSION_ACCESS_COARSE_LOCATION"), Starter.language.Value("PermissionDenied"))
            Wait For Msgbox_Result
            Return
        End If
    Next
    
    Log("PERMISSION_ACCESS_FINE_LOCATION=" & Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION))
    Log("PERMISSION_ACCESS_COARSE_LOCATION=" & Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_COARSE_LOCATION))
    
    If (Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION) Or Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_COARSE_LOCATION)) And _
                Starter.rp.Check("android.permission.BLUETOOTH_SCAN") And _
                Starter.rp.Check("android.permission.BLUETOOTH_CONNECT") Then
                
        CallSub(Starter , "InitBluetooth")
    End If
End Sub
 

hatzisn

Expert
Licensed User
Longtime User
You can always inform the user what permission is needed and why. If they choose not to grand the permission inform them that you cannot run the app.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…