Home » Android » callback not calling other methods

callback not calling other methods

Posted by: admin November 1, 2017 Leave a comment

Questions:

I am extending BluetoothGattCallback and had to override onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) method to meet the goal of writing to a file.

Inside this method I have a piece of code:

try {
    // file already open
    os.write(m.getBytes());
    //doWriteHere(m.getBytes)
}

When I run this code the way you see it, it successfully writes to a file. However, I would prefer to use doWriteHere() method.

When using the other method, nothing is written even if my method contains only this line: os.write(values).

Is there any reason why this is happening? Is there a way to call the method and make sure it executes the right thing?

EDIT:

public class ConnectCallback extends BluetoothGattCallback {

    public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
        super.onCharacteristicChanged(gatt, characteristic);
        Log.w(TAG, "Characteristic changed, " + characteristic.getUuid().toString());
        try {
            // file already open
            os.write(m.getBytes());
            //doWriteHere(m.getBytes)
        }

    public void doWriteHere(.... {
             os.write(values);
    }
}
Answers: