Battery notification not being received
See original GitHub issueBattery 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:
- Created 6 years ago
- Comments:13 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FYI You can close it by yourself next time. 😃
@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!