question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Battery notification not being received

See original GitHub issue

Battery notification not received


Connect to device, Set notifications for battery level change and custom characteristic
I am using a custom peripheral, which exposes a custom service & characteristic. I am trying to setup notifications on characteristic value changes for both the custom characteristic, and the battery level changes. When using the AOSP API directly, I can set notification for both, and I receive changes on both characteristics as expected. When I use this RxAndroidBle API, I no longer get notifications on the battery level changes. I do get the notification on the custom characteristic, though. I wonder why this is? See code below:
List<BluetoothGattCharacteristic> characteristics = new ArrayList<>();
characteristics.add(mSwitchCharacteristic);             // the custom Characteristic
characteristics.add(mBatteryLevelCharacteristic);   // battery level characteristic

Subscription notificationSubscription = connectionObservable
    .flatMap(rxBleConnection -> setupNotifications(rxBleConnection, characteristics))
    .doOnNext(notificationObservable -> {
        Log.i(TAG,"setupAllNotifications - Notification has been set up");
    })
    .subscribe(
        pair -> {
            Log.i(TAG,"setupAllNotifications - received notifications...");
            UUID uuid    = pair.first.getUuid();
            byte[] bytes = pair.second;
            BluetoothGattCharacteristic characteristic = null;

            if (mSwitchCharacteristic.getUuid().toString().equals(uuid.toString())){
                Log.i(TAG,"setupAllNotifications - received Switch char...");

                characteristic = mSwitchCharacteristic;
            }
            else if (mBatteryLevelCharacteristic.getUuid().toString().equals(uuid.toString())) {
                Log.i(TAG, "setupAllNotifications - received Battery char...");

                characteristic = mBatteryLevelCharacteristic;
            }

            if (characteristic != null) {
                Log.i(TAG,"setupAllNotifications - got characteristics, process..");

                onNotificationReceived(characteristic, bytes);      // just a method that processes the value
            }
            else{
                Log.i(TAG,"setupAllNotifications - failed to get characteristics, ignore.");
            }
        },
        throwable -> {
            Log.iTAG,"setupAllNotifications - throwable: "+throwable.getLocalizedMessage());

            onNotificationSetupFailure(characteristic, throwable);   // just a method that processes the value
        }
);

and the setupNotifications() method is as follows:
private Observable<Pair<BluetoothGattCharacteristic, byte[]>> setupNotifications(RxBleConnection connection,
                                                                                     List<BluetoothGattCharacteristic> characteristics) {
        Helper.getInstance().debug(TAG,"setupNotifications");

        return Observable.from(characteristics) // deal with every characteristic separately
                .filter(characteristic -> (characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) // filter characteristics that have notify property
                .flatMap(characteristic -> connection
                                .setupNotification(characteristic) // setup notification for each
                                .flatMap(observable -> observable), // to get the raw bytes from notification
                        Pair::new); // merge characteristic with byte[] to keep track from which characteristic the bytes came
    }

Actual result

  • Battery level changes are not received in the onNotificationReceived() method.
  • Changes to the custom characteristic are received in the onNotificationReceived() method

Expected result

  • changes to battery level should be received in the onNotificationReceived() method.
  • changes to the custom characteristic should be received in the onNotificationReceived() method

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dariuszseweryncommented, May 30, 2017

FYI You can close it by yourself next time. 😃

0reactions
chukscommented, May 29, 2017

@dariuszseweryn ok --it is working now. It takes a very long time before the battery notifications start coming in. No code changes needed. I think the delay must be from the peripheral side, since the custom starts immediately. Can close this, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 5 Fixes for Windows 10 Battery Low Notification Not ...
1. Set Low Battery Notification ... You need to check whether low battery notification is enabled or not on your PC. Here are...
Read more >
Fix: Windows 10/11 low battery notification not working
The Windows 10 low battery notification popup informs you that a laptop's battery is running out and needs charging.
Read more >
No Low battery notification in Windows 11/10 laptop
Scroll down and open the Battery tab. Click on the Critical Battery Notification and Low Battery Notification and check if they are On...
Read more >
5 Ways to Fix the Windows 10 Battery Low Notification When It ...
5 Ways to Fix the Windows 10 Battery Low Notification When It Won't Show ; Right-click Start > Settings> System > Notifications &...
Read more >
Windows 10 Low Battery Notification Not Working: How To Fix?
Solution 1: Check The Notifications · First, open the Settings Use the keyboard shortcut Win + I. · Click on System. · From...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found