How to implement battery-charge detection ?

Hello,

Seeing this 'Battery Widget with automatic charge detection' app -

I have looked at the API (developer.garmin.com/.../index.html) for the means to implement some of that functionality (namely looked for battery/charging related listeners/events),

And could not find anything and therefore I assume I have overlooked it somehow -

Does anyone have any idea where it is/how to detect charge begin/end events ?

  • you can tell by the state of

    System.getSystemStats().charging

    There's no listener or event.  You just have to keep looking.

    One thing to note is if you plug into a pc/mac, your app stops running, so you can't use this, but you can see if there was charging by checking if the battery level increased.

  • Hello again :) and thank you,

    Checking the System.getSystemStats().charging flag has been the method I have been using, and found it to be unreliable precisely for the reason you have mentioned (plug to PC/charger stops the app and all flags/state/etc in code are lost and I do not want to write them to file-system/props for performance reasons) -

    And this app somehow gave me the impression there was a better way to detect battery-charging-related events.