I can't receive broadcast on battery state change?

前端 未结 3 1463
野趣味
野趣味 2020-12-06 17:07

I am having the exact same problem as this post: Battery broadcast receiver doesn't work. But it seems no one has answered that question.

Here is my BroadcastRec

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 17:32

    From the documentation for ACTION_BATTERY_CHANGED:

    You can not receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver(). See ACTION_BATTERY_LOW, ACTION_BATTERY_OKAY, ACTION_POWER_CONNECTED, and ACTION_POWER_DISCONNECTED for distinct battery-related broadcasts that are sent and can be received through manifest receivers.

    There you have it: you must explicitly register for it from your Java code.

提交回复
热议问题