onCharacteristicWriteRequest @Override 是红色下划线
onCharacteristicWriteRequest the @Override is red underlined
我在 Android Things 项目中使用蓝牙,@Override 带有红色下划线。
@Override
public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
super.onCharacteristicWriteRequest(device, requestId, characteristic, preparedWrite, responseNeeded, offset, value);
Log.d(TAG, "onCharacteristicwriterequest UUID: " + characteristic.getUuid().toString());
mGattServer.notifyCharacteristicChanged(mBluetoothDevice, characteristic, true);
}
您是否期待 BluetoothGattCallback 方法?。如果是,则没有这样的回调方法。这是 BluetoothGattCallback
中可用的回调方法
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { //A request to Write has completed
if (status == BluetoothGatt.GATT_SUCCESS) { //See if the write was successful
AppLog.logError(TAG, "**ACTION_DATA_WRITTEN**" + characteristic);
broadcastUpdate(BLEConstants.ACTION_DATA_WRITTEN, characteristic); //Go broadcast an intent to say we have have written data
}
}
如果你想写一些东西到 BLE 你可以使用下面的方法
public void writeCharacteristic(BluetoothGattCharacteristic characteristic) {
try {
if (mBluetoothAdapter == null || mBluetoothGatt == null) { //Check that we have access to a Bluetooth radio
return;
}
int test = characteristic.getProperties(); //Get the properties of the characteristic
if ((test & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0 && (test & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) { //Check that the property is writable
return;
}
if (mBluetoothGatt.writeCharacteristic(characteristic)) { //Request the BluetoothGatt to do the Write
AppLog.logInfo(TAG, "****************WRITE CHARACTERISTIC SUCCESSFUL**" + (characteristic.getValue()[0] & 0xFF));//The request was accepted, this does not mean the write completed
/* if(characteristic.getUuid().toString().equalsIgnoreCase(getString(R.string.char_uuid_missed_connection))){
}*/
} else {
AppLog.logInfo(TAG, "writeCharacteristic failed "+ (characteristic.getValue()[0] & 0xFF)); //Write request was not accepted by the BluetoothGatt
}
} catch (Exception e) {
AppLog.logInfo(TAG, e.getMessage());
}
}
我在 Android Things 项目中使用蓝牙,@Override 带有红色下划线。
@Override
public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
super.onCharacteristicWriteRequest(device, requestId, characteristic, preparedWrite, responseNeeded, offset, value);
Log.d(TAG, "onCharacteristicwriterequest UUID: " + characteristic.getUuid().toString());
mGattServer.notifyCharacteristicChanged(mBluetoothDevice, characteristic, true);
}
您是否期待 BluetoothGattCallback 方法?。如果是,则没有这样的回调方法。这是 BluetoothGattCallback
中可用的回调方法 @Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { //A request to Write has completed
if (status == BluetoothGatt.GATT_SUCCESS) { //See if the write was successful
AppLog.logError(TAG, "**ACTION_DATA_WRITTEN**" + characteristic);
broadcastUpdate(BLEConstants.ACTION_DATA_WRITTEN, characteristic); //Go broadcast an intent to say we have have written data
}
}
如果你想写一些东西到 BLE 你可以使用下面的方法
public void writeCharacteristic(BluetoothGattCharacteristic characteristic) {
try {
if (mBluetoothAdapter == null || mBluetoothGatt == null) { //Check that we have access to a Bluetooth radio
return;
}
int test = characteristic.getProperties(); //Get the properties of the characteristic
if ((test & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0 && (test & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) { //Check that the property is writable
return;
}
if (mBluetoothGatt.writeCharacteristic(characteristic)) { //Request the BluetoothGatt to do the Write
AppLog.logInfo(TAG, "****************WRITE CHARACTERISTIC SUCCESSFUL**" + (characteristic.getValue()[0] & 0xFF));//The request was accepted, this does not mean the write completed
/* if(characteristic.getUuid().toString().equalsIgnoreCase(getString(R.string.char_uuid_missed_connection))){
}*/
} else {
AppLog.logInfo(TAG, "writeCharacteristic failed "+ (characteristic.getValue()[0] & 0xFF)); //Write request was not accepted by the BluetoothGatt
}
} catch (Exception e) {
AppLog.logInfo(TAG, e.getMessage());
}
}