所以在得到
Paired Devices
,找到您的设备并按如下方式连接:
BluetoothAdapter bleAdapter = ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter();
Set<BluetoothDevice> pairedDevices = bleAdapter.getBondedDevices();
for(BluetoothDevice d: pairedDevices){
if(d.getAddress().equals("Your Device MAC")){
d.connectGatt(MainActivity.this, true, new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt
gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
switch (newState) {
case BluetoothProfile.STATE_CONNECTED:
Log.i("GattCallback", "connected");
gatt.getServices();
break;
case BluetoothProfile.STATE_DISCONNECTED:
Log.i("GattCallback", "Disconnected");
break;
}
}
});
}
}
实现
Auto Connect
设置
自动连接
变量
true
在里面
device.connectGatt(context, Auto Connect, BluetoothGattCallback);
.