android BluetoothGatt.writeCharacteristic()写入返回false

http://stackoverflow.com/questions/23879869/bluetoothgatt-writecharacteristic-always-returns-false
服务和写入特性在每次需要写入的时候重新获取,只有BluetoothGatt反复使用:

byte[] data_to_write; // Your data
BluetoothManager mBluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SREVICE);
BluetoothAdapter mBluetoothAdapter = mBluetoothManager.getAdapter();
BluetoothDevice mDevice = mBluetoothAdapter.getRemoteDevice(....);
BluetoothGatt mBG = mDevice.connectGatt(....);

BluetoothGattService mSVC = mBG.getService(service_uuid);
BluetoothGattCharacteristic mCH = mSVC.getCharacteristic(characteristic_uuid);
mCH.setValue(data_to_write);
mBG.writeCharacteristic(mCH);

你可能感兴趣的:(android BluetoothGatt.writeCharacteristic()写入返回false)