Android Question Hidden bluetooth pairing notification

Status
Not open for further replies.

Arf

Well-Known Member
Licensed User
Longtime User
When I first pair my bluetooth device to my tablet via my app, I get a "Accept Pairing?" popup.
No PIN is required as the device I am connecting to is in JustWorks PIN mode, so it's just a YES or NO answer.

My app is a fullscreen app, and on some devices the "Acccept Pairing" notification doesn't pop up on top of my app, so users are going to not know it's there and this spells trouble.

I found the BtAutoPair library, tried it but it uses a PIN code and pairing with my device always fails no matter what pin I use, as it doesn't need a PIN.

so 2 questions:
1: Is there any way I can force the pairing notification to go on top of my app always?
2: I found some code here: http://stackoverflow.com/a/30362554
One line is device.setPairingConfirmation(true), which looks promising for me to use. So my question here is, is there any way I can run this code in B4A, or would I have to make a library to do that? I've never made a library before and know little about java so I am hoping there might be some inline method I can use.

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Create a service named BTPair.

1. Add this code to the manifest editor:
B4X:
AddReceiverText(BTPair,
<intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
</intent-filter>)

2. In Service_Start of that service:
B4X:
If StartingIntent.Action = "ACTION_PAIRING_REQUEST" Then
Dim jo As JavaObject = StartingIntent
Dim device As JavaObject = jo.RunMethod("getParcelableExtra", Array("android.bluetooth.device.extra.DEVICE"))
device.RunMethod("setPairingConfirmation", Array(True))
 
Last edited:
Reactions: Arf
Upvote 0
when i add your code to manifest erorr will apear,my inserting code is like this,is it incorrect?

 
Upvote 0
thanks Erel, so it should be like this?

XML:
AddManifestText(
<intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
</intent-filter>
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)

SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "AraElectrodeLab")
CreateResourceFromFile(Macro, Themes.DarkTheme)
 
Upvote 0
Thanks, but Erel said that AddRecivedtext not should be in manifest.

you said that it be " AddReciveText( " not "AddReciveText(BTPair,"


which is correct?
 
Upvote 0
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…