Android蓝牙LE写入无法正常工作

时间:2018-06-27 00:12:12

标签: android

我是App开发的新手。我正在开发一个Android应用程序,用于读写蓝牙模块(Microchip RN4871)。使用BlutoothLeGatt示例程序,我可以扫描并连接到Bluetooth模块。当我写作时,它正在接受。没有错误信息。当我按下按钮时,我进入了android studio的运行窗口。

  

D / ViewRootImpl @ 70a8843 [DeviceControlActivity]:ViewPostImeInputStage   processPointer 0 D / ViewRootImpl @ 70a8843 [DeviceControlActivity]:   ViewPostImeInputStage processPointer 1

我正在使用以下对象进行写入。

  /get the write characteristic from the service/
    public void writeCustomCharacteristic(int value) {
        if (mBluetoothAdapter == null || mBluetoothGatt == null) {
            Log.w(TAG, "BluetoothAdapter not initialized");
            return;
        }
   /check if the service is available on the device/
        BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("49535343-fe7d-4ae5-8fa9-9fafd205e455"));
        if(mCustomService == null){
            Log.w(TAG, "Custom BLE Service not found");
            return;
        }
           /get the write characteristic from the service/
        BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("49535343-8841-43f4-a8d4-ecbe34729bb3"));
        mWriteCharacteristic.setValue(value,android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);
        if(mBluetoothGatt.writeCharacteristic(mWriteCharacteristic) == false){
            Log.w(TAG, "Failed to write characteristic");
        }
    }

我知道问题出在mWriteCharacteristic.setValue(value,android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);

请让我知道,我在此指令上犯了什么错误。

0 个答案:

没有答案