android ble 发送指令,Android – 如何通过蓝牙低能耗(BLE)链接发送数据?
我能够发现,连接到蓝牙.源代码 – –通过蓝牙连接到远程设备://Get the device by its serial numberbdDevice = mBluetoothAdapter.getRemoteDevice(blackBox);//for ble connectionbdDevice.connectGatt(getApplicationContext(), true, mGatt
我能够发现,连接到蓝牙.
源代码 – –
通过蓝牙连接到远程设备:
//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设备将通过广播进行响应
我的应用程序可以接收的数据.
更多推荐
所有评论(0)