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模式不同会对发送有很大影响。

更多相关文章

  1. android广播 demo
  2. BroadcastReceiver
  3. 简单创建Android(安卓)MVVM模式代码
  4. 发送短信之分割短信 SMSManager
  5. Android全局异常捕捉
  6. 使用Notification发送消息通知
  7. 2020年最新阿里、字节、腾讯、京东等一线大厂高频面试(Android岗)
  8. Android使用Socket(Tcp/Udp)协议进行数据传输(传输大文件)
  9. 说说Android的MVP模式

随机推荐

  1. AndroidStudio2.2.3设置
  2. Android(安卓)Manifest.xml文件解析
  3. Android之MainActivity类
  4. Android(安卓)studio 多渠道打包(超简洁
  5. [转]Android(安卓)Test Auto Test Mu…
  6. 安卓 Activity(2) 四大启动方式
  7. android应用程序内存分析
  8. [置顶] android scrollview 滑动到顶端或
  9. Android中保存Activity的状态
  10. 三种解析xml的方式