我尝试将数据从我的Android应用程序发送到蓝牙设备,这是我的send_data_code:
public boolean sendData(byte[] data) {
BluetoothGattService btGService = mBluetoothGatt.getService(JumpConstants.UUID_SERVICE_WRITE);
if(btGService==null){
Log.d("crx","btGService is null!");
return false;
}
Log.d("crx","btGService="+btGService);
BluetoothGattCharacteristic write_characteristic = btGService.getCharacteristic(JumpConstants.UUID_CHRACTERISTIC_WRITE);
Log.d("crx","btGCharacteristic="+write_characteristic);
if(write_characteristic!=null){
write_characteristic.setValue(data);
return mBluetoothGatt.writeCharacteristic(write_characteristic);
}
return false;
}
有时代码工作正常,但有时候" write_characteristic"将为null。我不知道为什么" write_characteristic"将是空的。
答案 0 :(得分:0)
这是硬件问题。我与之通信的蓝牙硬件不稳定,这就是为什么代码有时可以正常工作但有时却不能正常工作的原因。