Android BroadcastReceiver not working after install

帅比萌擦擦* 提交于 2019-12-01 06:34:57

Is there a reason these phones need to be restarted before the BroadcaseReceiver can pick anything up?

Assuming that your application has its BroadcastReceiver registered in the manifest for the PHONE_STATE broadcast, it should work immediately upon install. If it does not, it feels like a buggy ROM to me.

Is there a way I can detect if it isn't running and manually "start" the BroadcaseReceiver?

No, mostly because it's not running, usually, even when things are working. An instance of your BroadcastReceiver is created at the point of the Intent - <intent-filter> match, it is called with onReceive(), and the BroadcastReceiver is disposed of once onReceive() returns.

To expand on the issue: starting from Android 3.1, installed applications are put in "STOPPED" state. To invoke BroadcastReceiver(s) from stopped application an additional broadcast intent flag is required.

More details: http://developer.android.com/sdk/android-3.1.html#launchcontrols

I created FLAG_INCLUDE_STOPPED_PACKAGES constant (=32) in my application (for pre-Android 3.1) and just add it to my broadcast intent intent.addFlags(FLAG_INCLUDE_STOPPED_PACKAGES);

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