扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
今天就跟大家聊聊有关Android应用中蓝牙自动匹配PIN码时怎么跳过用户交互,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
1.断开已配对设备
最后在项目中发现没有用。这里就先记录一下。
//得到配对的设备列表,清除已配对的设备 public void removePairDevice() { if (mBluetoothAdapter != null) { //mBluetoothAdapter初始化方式 mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); //这个就是获取已配对蓝牙列表的方法 SetbondedDevices = mBluetoothAdapter.getBondedDevices(); for (BluetoothDevice device : bondedDevices) { //这里可以通过device.getName() device.getAddress()来判断是否是自己需要断开的设备 unpairDevice(device); } } } //反射来调用BluetoothDevice.removeBond取消设备的配对 private void unpairDevice(BluetoothDevice device) { try { Method m = device.getClass().getMethod("removeBond", (Class[]) null); m.invoke(device, (Object[]) null); } catch (Exception e) { Log.e("mate", e.getMessage()); } }
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流