I am working on an App that connects the android device with another device (CAN modules) over Bluetooth.
I pair previously unpaired devices like this:
Method m = device.getClass().getMethod("createBond", (Class[]) null);
m.invoke(device, (Object[]) null);
Run Code Online (Sandbox Code Playgroud)
Which works like a charm.
There is an issue though. The CAN Modules are set up in a way that you don't need the pin stuff or any other form of pairing confirmation, you just say that you want to pair with the device and it'll do so. Now, what happens if my App tries to connect to a Bluetooth device that is not a CAN Module, like a phone for example?
In that case, a Dialog appears asking the User to confirm the pairing. I don't mind the dialog, BUT I would like to react to the "Cancel" button in some way.
To sum it up:
I want to call method doSomething() when the User presses Cancel on the Bluetooth Pairing Confirmation Dialog. Is this possible?
你应该听ACTION_BOND_STATE_CHANGED Intent(我希望你知道如何注册 BroadcastReceiver 并使用它们)。
上面由 system(BluetoothService) 广播的动作还包含Current Bond State和Previous Bond State。
共有三种债券状态。
BOND_BONDED 表示远程设备已绑定(配对)。
BOND_BONDING 表示正在与远程设备进行绑定(配对)。
BOND_NONE 表示远程设备未绑定(配对)。
在您的情况下,您将收到BOND_BONDING >> BOND_NONEPassKey 对话框上的取消按钮以及 PassKey 对话框上BOND_BONDING >> BOND_BONDED的配对按钮
| 归档时间: |
|
| 查看次数: |
3439 次 |
| 最近记录: |