Android Question Need android.permission.BLUETOOTH_CONNECT in android 12

ppgirl

Member
Licensed User
Longtime User
Dear Erel,

Now (Sept. of 2022), Android 12 is Google Play basic requirement. I need update my app with Bluetooth function to Android 12.
I found the permissions about bluetooth add "android.permission.BLUETOOTH_SCAN" ,"android.permission.BLUETOOTH_CONNECT" and "android.permission.BLUETOOTH_ADVERTISE" in API31. Using the API31 , App will not connect if has not "android.permission.BLUETOOTH_CONNECT" permission.
I try to use rp.CheckAndRequest("android.permission.BLUETOOTH_CONNECT") to call the RuntimePermissions page , but it looks no function.
So I want know the right way to call those new runtime permissions , Thanks in advance!

Yang
 
When asking questions please do not address them to an individual unless it is absolutely necessary.

Have you tried putting the following in your manifest?
B4X: Copy
AddPermission(android.permission.BLUETOOTH_ADVERTISE)
AddPermission(android.permission.BLUETOOTH_CONNECT)
AddPermission(android.permission.BLUETOOTH_SCAN)
 
Upvote 0
@agraham , you are friendly.

I have added those in manifest editor, there are lines in the AndroidManifest.xml.
...
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
...

PS, This is the log of connect failure.
java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for android.content.AttributionSource@331e1d8b: HidDeviceService$BluetoothHidDeviceBinder
 
Upvote 0
@agraham,

I find my bug and the CheckAndRequest work right.

I make connecting before "Wait For Activity_PermissionResult" event , so the connecting is failure.

public Sub checkConnectPermission
...
rp.CheckAndRequest("android.permission.BLUETOOTH_CONNECT")
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission, The App is about to EXIT!", False)
Activity.Finish
End If
...
end sub

public Sub main
...
checkConnectPermission
connect()
...
end sub
 
Upvote 0
Back
Top