在AndroidManifest.xml中添加后,意图ACTION_POWER_CONNECTED无法正常工作 [英] Intent ACTION_POWER_CONNECTED not working when added inside AndroidManifest.xml
问题描述
我正在应用程序的AndroidManifest.xml文件中添加电池连接和断开事件的意图过滤器,并按此链接中的说明注册PowerConnection接收器:
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.
推荐答案
如果您使用的是API 26及更高版本,则此方法无效. 阅读此内容: https://developer.android.com/about/versions/oreo/background 我也尝试解决类似的问题.现在创建了一个前台服务,该服务从启动时开始并监视充电器的状态.
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.
这篇关于在AndroidManifest.xml中添加后,意图ACTION_POWER_CONNECTED无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!