Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify of Characteristic Change Fails on 2.4.0 #168

Open
sean7512 opened this issue Nov 17, 2022 · 12 comments
Open

Notify of Characteristic Change Fails on 2.4.0 #168

sean7512 opened this issue Nov 17, 2022 · 12 comments

Comments

@sean7512
Copy link

When using version 2.3.4, everything works fine; however updating to 2.4.0 breaks notifying.

Inside of BluetoothPeripheralManager is the following:

public boolean notifyCharacteristicChanged(@NotNull final byte[] value, @NotNull final BluetoothGattCharacteristic characteristic) {
    Objects.requireNonNull(value, CHARACTERISTIC_VALUE_IS_NULL);
    Objects.requireNonNull(characteristic, CHARACTERISTIC_IS_NULL);

    if (doesNotSupportNotifying(characteristic)) return false;

    boolean result = true;
    for (BluetoothCentral device : getConnectedCentrals()) {
        if (!notifyCharacteristicChanged(value, device, characteristic)) {
            result = false;
        }
    }
    return result;
}

When using 2.4.0, the getConnectedCentrals() call is returning an empty list; however in 2.3.4, it is returning the centrals correctly.

@sean7512
Copy link
Author

I think the call in the loop may need changed to getCentralsWantingNotifications(). Unfortunately, I have run out of time today to continue testing.

@weliem
Copy link
Owner

weliem commented Nov 26, 2022

I think this is related to the other issues you are reporting. In 2.4.0 the logic for getting connected devices was changed and now uses the library internal lists rather than the OS.

@sean7512
Copy link
Author

I don't think so, because it doesn't work even if I turn off advertising. There are 2 methods for notifying of characteristic changed, 1 that takes a central to notify and 1 that doesn't. On the one that doesn't, it is still querying the OS and not using the internal list, as it should. When using the debugger, getCentralsWantingNotifications(characteristic) returns the expected values, but the method is calling getConnectedCentrals() which is returning an empty list.

@weliem
Copy link
Owner

weliem commented Nov 29, 2022

I tried the example (https://github.com/weliem/bluetooth-server-example) and everything seems fine, but that is of course only a peripheral.

@sean7512
Copy link
Author

I can submit a PR soon, I have a local code change that is working, its a very minor change.

Thanks for continuing to help me.

@sean7512
Copy link
Author

sean7512 commented Dec 1, 2022

Another interesting finding.....so it gets removed from the internal list because of a random onConnectionStateChange callback that says it was disconnected. If you use bluetoothManager.getConnectionState(device, BluetoothProfile.GATT) in that call, it will return that it is connected, contradicting the notification. I wonder if we can only fall down and call handleDeviceDisconnected(device) if the OS tells us it was disconnected?

@archie94
Copy link

Is there any update on this? We are facing this problem too.

@archie94
Copy link

I had to revert to version 2.1.2
We were not getting this problem on debug variants but on release variants (2.4.0 and 2.3.5) onCharacteristicUpdate was not being called.

@weliem
Copy link
Owner

weliem commented Dec 14, 2022

@archie94 are you sure this is the same issue? There is no onCharacteristicUpdate in BluetoothPeripheralManagerCallback....

@archie94
Copy link

Umm .. this one

    public void onCharacteristicUpdate(@NotNull BluetoothPeripheral peripheral, @NotNull byte[] value, @NotNull BluetoothGattCharacteristic characteristic, @NotNull GattStatus status) {}

in BluetoothPeripheralCallback

Also may be related but from Nordic BLE library:

NordicSemiconductor/Android-BLE-Library#395

@weliem
Copy link
Owner

weliem commented Jan 4, 2023

@archie94 , you are referring to an issue with a BluetoothPeripheral but @sean7512 is referring to an issue when notifying to a BluetoothCentral....

Please open a new issue if you still are having this issue.

@strike76
Copy link

I had to revert to version 2.1.2 We were not getting this problem on debug variants but on release variants (2.4.0 and 2.3.5) onCharacteristicUpdate was not being called.

Same problem here. No problem with debug release, i need to use 2.2.3 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants