安卓蓝牙配对,如何得到配对状态的标志

决意 2017-05-22 08:31:29
最近在做安卓蓝牙开发的时候,碰到蓝牙配对的问题,想得到配对成功或者失败的标识位之后刷新附近设备和已配对设备的列表,但是从BluetoothDevice.BOND_NONE,BluetoothDevice.BOND_BONDING,BluetoothDevice.BOND_BONDED这3个广播并不能得到例如配对成功的广播,在请求配对的时候,就能检测到BluetoothDevice.BOND_BONDED这个广播了,还有其他的方法能够得到蓝牙配对与否的回调么
...全文
274 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
南瓜饼 2017-05-24
  • 打赏
  • 举报
回复
/** * 蓝牙接收广播 */ private BroadcastReceiver m_Receiver = new BroadcastReceiver() { // 接收 public void onReceive(Context context, Intent intent) { String action = intent.getAction(); // 状态改变时 if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (device.getAddress().equals(m_strDeviceAddress)) { switch (device.getBondState()) { case BluetoothDevice.BOND_BONDING:// 正在配对 break; case BluetoothDevice.BOND_BONDED:// 配对结束 break; case BluetoothDevice.BOND_NONE:// 取消配对/未配对 break; default: break; } } } } };
伊怡已易 2017-05-24
  • 打赏
  • 举报
回复
试试在BluetoothNortified回调里用btDevice.getBondState()判断

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧