Intent ACTION_POWER_CONNECTED not working when added inside AndroidManifest.xml [duplicate]

我的未来我决定 提交于 2020-02-08 09:37:49

问题


I am adding intent filter for battery power connected and disconnected events inside my app's AndroidManifest.xml file and registering PowerConnection receiver as given in this link: https://developer.android.com/training/monitoring-device-state/battery-monitoring.html. But when I connect and disconnect my device with power source the receiver not invoked. When I am registering the same receiver programatically within my activity class, it is working fine. I want to invoke this receiver with power events when my app is not running by registering it manually inside AndroidManifest.xml. Please help me on this.


回答1:


If you are using API 26 and above, this method does not work. Read this: https://developer.android.com/about/versions/oreo/background I am also try to sovle similar problem. Now created a foreground service that starts at boot and monitors the status of the charger.



来源:https://stackoverflow.com/questions/47618775/intent-action-power-connected-not-working-when-added-inside-androidmanifest-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!