####初始化
bleManager = BleManager.getInstance();
bleManager.init(this);
####扫描指定名称设备、并连接
bleManager.connectDevice(
DEVICE_NAME,
TIME_OUT,
new BleManagerConnectCallback() {
@Override
public void onConnectSuccess(BluetoothGatt gatt, int status) {
Log.i(TAG, "连接成功!");
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
Log.i(TAG, "服务被发现!");
}
@Override
public void onConnectFailure(BleException exception) {
Log.i(TAG, "连接失败或连接中断:" + '\n' + exception.toString());
}
});
####notify
bleManager.notifyDevice(
UUID_SERVICE_LISTEN,
UUID_LISTEN_NOTIFY,
UUID_CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR,
new B