Hi,
I have a problem with these 2 statements when I need to use SDK-31:
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:
I have a problem with these 2 statements when I need to use SDK-31:
- 29 - BluetoothAdmin.StartDiscovery and BLEManager.StartScan require the ACCESS_FINE_LOCATION permission. Previously the COARSE location was enough.
- 31 - The user can limit the location permission to coarse even when fine is requested. Your code should handle this case: https://www.b4x.com/android/forum/threads/b4a-v11-50-has-been-released.139288/#content
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