android 蓝牙发送数据
16lz
2021-01-26
private BluetoothGattCharacteristic getSupportedCharacteristic(String uuidService, String uuidChar) { BluetoothGattCharacteristic alertLevel = null; if (mGatt != null) { BluetoothGattService linkLossService = mGatt.getService(UUID.fromString(uuidService)); if (linkLossService == null) { return null; } alertLevel = linkLossService.getCharacteristic(UUID.fromString(uuidChar)); } return alertLevel; }
private boolean sendMsg(byte[] value) { BluetoothGattCharacteristic characteristic = BletoothManager.getInstance().getSupportedCharacteristic(BletoothManager.UUID_SERVICE, BletoothManager.UUID_WRITE); if (characteristic == null) { Log.e(TAG, "write characteristic cannot find"); return false; } mGatt.setCharacteristicNotification(characteristic, true); characteristic.setValue(value); characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); boolean result = mGatt.writeCharacteristic(characteristic); return result; }
注意点是:setWriteType模式不同会对发送有很大影响。
更多相关文章
- android广播 demo
- BroadcastReceiver
- 简单创建Android(安卓)MVVM模式代码
- 发送短信之分割短信 SMSManager
- Android全局异常捕捉
- 使用Notification发送消息通知
- 2020年最新阿里、字节、腾讯、京东等一线大厂高频面试(Android岗)
- Android使用Socket(Tcp/Udp)协议进行数据传输(传输大文件)
- 说说Android的MVP模式