This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

battery level notification bad for custom android app

I tried to make android app for nrf51822 hrm proj.The app flows like this: scan--connect--discover service-- setnotification for every characteristic. The Hrm char was firstly notified and I got right updated values everytime. However when I did the same setnotification operation for battery level char secondly, I cannot get level data changed notification.
I am sure the setcharacteristicnotificaion() function is ok, since hrm data can be got rightly.But what's wrong when it came to battery level notification ? As a newbie I am not so familiar with the nrf-tool box android app source. I tried to transplant the code for battery notification into my app, but nothing help,maybe I didnot got the right flow order or code structure. How to fix that? What 's special with battery level characteristic? To make it simple, I noly enabled to notification: hrm characteristic and battery characteristic.

Parents
  • Hey Bui, thanks for the reply. The general flow is : onServicesDiscovered() --->findService(); and findService() is: public void findService(BluetoothGatt gatt) { List gattServices = gatt.getServices(); ...

    	for (BluetoothGattService gattService : gattServices)
    	{
    	if(gattService.getUuid().toString().equalsIgnoreCase(BATTERY_SERVICE.toString()))
            {
                List<BluetoothGattCharacteristic> gattCharacteristics =
                        gattService.getCharacteristics();
              
                for (BluetoothGattCharacteristic gattCharacteristic :
                        gattCharacteristics)
                {
                    if(gattCharacteristic.getUuid().toString().equalsIgnoreCase(BATTERY_LEVEL_CHARACTERISTIC.toString()))
                    {
                        
                       setCharacteristicNotification(gatt,gattCharacteristic, true);
                       
                        break;
                    }
    
                }
            }
       else {...}//hrm service
    	}
        broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED, gatt.getDevice().getAddress() , gatt.getDevice().getName());
    }
    
Reply Children
No Data
Related