写操作不能与android Ble上的某些设备一起使用

时间:2015-10-12 13:46:57

标签: android bluetooth-lowenergy android-ble

我正在尝试在A& D设备的特征中写入一个值。在某些设备上,它工作正常,但在其他设备中,写操作不起作用。 我尝试本地化问题,因此我在onWriteCharacteristic类的BluetoothService回调中添加了此代码:

@Override
        public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {

            if (status == BluetoothGatt.GATT_SUCCESS) {
                Log.e(TAG, "successful characteristic write");
            } else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {

                if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {

                    Log.e(TAG, "no bounded device found");
                } else {
                    Log.e(TAG, "GATT INSUFFICIENT AUTHENTICATION");
                }
            } else if(status == BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED){
                Log.e(TAG, "GATT_REQUEST_NOT_SUPPORTED");
            } else if(status == BluetoothGatt.GATT_INVALID_OFFSET){
                Log.e(TAG, "GATT_INVALID_OFFSET");
            } else if(status == BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION){
                Log.e(TAG, "GATT_INSUFFICIENT_ENCRYPTION");
            } else if(status == BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER){
                Log.e(TAG, "CONNECTION_PRIORITY_LOW_POWER");
            } else if(status == BluetoothGatt.CONNECTION_PRIORITY_HIGH){
                Log.e(TAG, "CONNECTION_PRIORITY_HIGH");
            } else if(status == BluetoothGatt.GATT_WRITE_NOT_PERMITTED){
                Log.e(TAG, "no write permission");
            } else if(status == BluetoothGatt.GATT_CONNECTION_CONGESTED){
                Log.e(TAG, "problem with remote device");
            } else if (status == BluetoothGatt.GATT_FAILURE) {
                Log.e(TAG, "GATT failure");
            } else if(status == BluetoothGatt.GATT){
                Log.e(TAG, "GATT");
            }
            else {

                Log.e(TAG, "unknown error in write characteristic" + characteristic.getUuid().toString());
            }
        }

但它有一个未知的错误

0 个答案:

没有答案