Detect Changing Battery state at every percentage in android

前端 未结 1 546
傲寒
傲寒 2020-12-09 22:14

i want to detect battery change at every percentage. I am able to detect battery level once with broadcast receiver. But its not updating value automatically when % change f

1条回答
  •  时光说笑
    2020-12-09 23:10

    First, you do not need the BATTERY_STATS permission.

    Second, the very first line of your onReceive() unregisters your BroadcastReceiver, thereby preventing you from getting any further updates.

    Third, there is no guarantee that you will have battery information delivered to you for each and every 1% change. Many Motorola phones, for example, only send ACTION_BATTERY_CHANGED every 10% until the battery gets low. The decision on how frequently to broadcast ACTION_BATTERY_CHANGED is up to the device manufacturer, not you.

    0 讨论(0)
提交回复
热议问题