之前写过ble的连接,但是最近的开发板蓝牙无法连接,但连接老设备还是可行的。
资料发现开发版蓝牙为双模蓝牙,需添入一段以下代码。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
mBluetoothGatt = device.connectGatt(this, false, mGattCallback, BluetoothDevice.TRANSPORT_LE);
} else {
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
}
运行后解决问题,记录一下。