android - working with broadcastReceiver on androi

2019-07-18 22:21发布

i'm having a problem on android ICS (version 4) and broadcastReceiver . please help:

i'm trying to listen to a simple intent of network connectivity change . i've tried the next tutorial (with the broadcastReceiver defined in the manifest alone - the first part of the website ) : http://www.xinotes.org/notes/note/1526/ on ICS , it doesn't capture any intent , and on any other version it works just fine .

can anyone please tell me what's wrong? do i need to add a new intent filter other than the one that listens to CONNECTIVITY_CHANGE ? has google blocked listening to such intents on ICS ? are there any other new rules for ICS that have changed ?

i think that other broadcastReceivers also won't work on ICS using the manifest .

1条回答
放我归山
2楼-- · 2019-07-18 23:12

The sample code shown in that link may work, but it needs an activity. On Android 3.1+, an application is installed in a "stopped" state. While in that state, no BroadcastReceiver will work, until the user manually launches an activity from the application. The application will return to this "stopped" state if the user force-stops the application from Settings.

So, add an activity to your project, launch it once, and then see if your receiver works.

查看更多
登录 后发表回答