根据远程蓝牙设备(remote devices)的要求,手机端发起与远程蓝牙设备Bluetooth remote Device的配对有两种情况
第一种:配对时需要pin码(pin request event)即有配对请求pairing request :所对应的action为 : BluetoothDevice.ACTION_PAIRING_REQUEST。
根据远程设备所携带的type信息判断是否可以获取到pairingkey
type值通过BluetoothDevice.EXTRA_PAIRING_VARIANT获取到
int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
BluetoothDevice.ERROR);
pairingkey通过BluetoothDevice.EXTRA_PAIRING_KEY获取到
int pairingKey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,
BluetoothDevice.ERROR);
如果type(int型数值)属于以下3种类型:
则表示远程设备(remote device)本身携带有配对码pairingkey,可以通过BluetoothDevice.EXTRA_PAIRING_KEY获取到配对码
如果type不属于以上3种类型,则表示远程设备不会携带pairingkey配对码,必须要用户自己手动输入:The user will be prompted to enter a pin or an app will enter a pin for user
第二种:不需要pin码(create bond)没有配对请求(对应的设备有scp960,蓝牙耳机等),此时远程设备不需要鉴权,可以直接使用(just works)
所对应的action为:BluetoothDevice.ACTION_BOND_STATE_CHANGED
监听action的类为BluetoothPairingRequest.java,配对弹窗为BluetoothPairingDialog.java。字段信息存在于BluetoothDevice.java中
总结来说如果不以action为区分的话,配对分为三种情况
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有