Android 如何向BLE发送AE A7 04 00 05 09 BC B7命令

Android 如何向BLE发送AE A7 04 00 05 09 BC B7命令,android,bluetooth-lowenergy,android-bluetooth,android-ble,Android,Bluetooth Lowenergy,Android Bluetooth,Android Ble,我需要发送AE A7 04 00 05 09 BC B7命令到BLE设备。你能帮我管理一下吗?我的意思是,连接到设备后,我要做什么以及如何做 public void WriteValue(String strValue) { mNotifyCharacteristic.setValue("AE A7 04 00 05 09 BC B7".getBytes()); mBluetoothGatt.writeCharacteristic(mNot

我需要发送AE A7 04 00 05 09 BC B7命令到BLE设备。你能帮我管理一下吗?我的意思是,连接到设备后,我要做什么以及如何做

public void WriteValue(String strValue)
    {
            mNotifyCharacteristic.setValue("AE A7 04 00 05 09 BC B7".getBytes());
            mBluetoothGatt.writeCharacteristic(mNotifyCharacteristic);
            boolean sendStatus = mBluetoothGatt.writeCharacteristic(mNotifyCharacteristic);"+mNotifyCharacteristic.getProperties());
    }

@Override
        public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
                                        int status)
        {
            Log.d("TESTING","status !!!= "+status);
        }

您需要使用十六进制到字节数组的转换将字符串正确地转换为字节数组,而不仅仅是获取每个字符的ascii值。

我不清楚您要发送什么。这是一个字符串吗?我如何理解我只能发送字节数组,所以最后我要做这个转换:mNotifyCharacteristic.setValue(“AE A7 04 00 05 09 BC B7.getBytes());MBlueTothGatt.写特征(mNotifyCharacteristic);但我不确定我是否正确地完成了发送过程……尝试一些写操作很容易。是否有写入(字节)?是的,但我得到的状态为0,因此有些错误,请询问他们您为您提到的“字符串”发送了多少字节。按照现在的方式,您将发送23个字节。但可能是接收器只需要8个字节。很可能。你能举个例子吗?目前我是这样做的:public void WriteValue(String strValue){mNotifyCharacteristic.setValue(strValue.getBytes());mbluetothgatt.writeCharacteristic(mNotifyCharacteristic);}这里有答案。但请确保首先删除字符串中的空格。我已将代码更改为此代码,但结果相同:string s=“AEA70400509BCB7”;byte[]b=新的BigInteger(s,16).toByteArray();mNotifyCharacteristic.设定值(b);MBlueTothGatt.写特征(mNotifyCharacteristic);