android 蓝牙 配对 取消pin 配对 转

你的代码能收到ACTION_PAIRING_REQUEST intent消息么?
如果不能,那就是你的broadcast receiver的问题,和蓝牙无关。
如果能,那继续下一步,在收到ACTION_PAIRING_REQUEST的intent的时候,创建一个bluetooth device,直接调用bluetooth device的setpin()方法就可以了,具体的调用,在上面的代码出处有详细的范本。
http://www.eoeandroid.com/thread-74683-1-1.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android取消蓝牙设备配对的广播可以使用以下步骤: 1. 首先,需要注册一个广播接收器来接收配对状态的更改,可以使用以下代码实现: ``` private final BroadcastReceiver mPairingRequestReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); int pairingVariant = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR); if (pairingVariant == BluetoothDevice.PAIRING_VARIANT_PIN) { // Handle PIN pairing request } else if (pairingVariant == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION) { // Handle passkey confirmation pairing request } } } }; ``` 2. 然后,当需要取消配对时,可以使用以下代码: ``` BluetoothDevice device = ...; // 要取消配对的设备 Method m = device.getClass().getMethod("removeBond", (Class[]) null); m.invoke(device, (Object[]) null); ``` 这将调用BluetoothDevice类中的removeBond()方法来取消设备的配对。 3. 最后,需要在应用程序中发送取消配对广播以通知系统已取消配对。可以使用以下代码: ``` Intent cancelPairingIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); cancelPairingIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); cancelPairingIntent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); sendBroadcast(cancelPairingIntent); ``` 这将发送一个指示设备已取消配对的广播。注意,这将触发mPairingRequestReceiver接收器,因此需要在接收器中处理此情况。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值