最近用 github.com/dingjikerbo/Android-BluetoothKit 這個庫做了一個demo。踩了非常多的坑。
記錄一下赢赊。
連接失敗問題
修改系統(tǒng)庫中的源碼(最好是把作者的庫,down下來)
BleConnectWorker#openGatt
if (Build.VERSION.SDK_INT >= 26) {
mBluetoothGatt = mBluetoothDevice.connectGatt(context, false, callback, BluetoothDevice.TRANSPORT_AUTO);
} else if (Version.isMarshmallow()) {
mBluetoothGatt = mBluetoothDevice.connectGatt(context, false, callback, BluetoothDevice.TRANSPORT_LE);
} else {
mBluetoothGatt = mBluetoothDevice.connectGatt(context, false, callback);
}
掃描不到的問題
實(shí)測在android 10上,需要打開位置信息砾隅。
單純的申請位置動態(tài)權(quán)限不行,需要引導(dǎo)客戶打開位置信息抖所。
系統(tǒng)設(shè)置-位置信息-位置信息開
image.png