我能够发现,连接到蓝牙.

源代码 – –

通过蓝牙连接到远程设备:

//Get the device by its serial number

bdDevice = mBluetoothAdapter.getRemoteDevice(blackBox);

//for ble connection

bdDevice.connectGatt(getApplicationContext(), true, mGattCallback);

Gatt CallBack状态:

private BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {

@Override

public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {

//Connection established

if (status == BluetoothGatt.GATT_SUCCESS

&& newState == BluetoothProfile.STATE_CONNECTED) {

//Discover services

gatt.discoverServices();

} else if (status == BluetoothGatt.GATT_SUCCESS

&& newState == BluetoothProfile.STATE_DISCONNECTED) {

//Handle a disconnect event

}

}

@Override

public void onServicesDiscovered(BluetoothGatt gatt, int status) {

//Now we can start reading/writing characteristics

}

};

现在我想发送命令到远程BLE设备,但不知道如何做到这一点.

一旦将命令发送到BLE设备,BLE设备将通过广播进行响应

我的应用程序可以接收的数据.

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐