I create a project which only includes one receiver. Some codes are like below:
<receiver android:name=".InputReceive" android.enabled = "true">
<intent-filter>
<action android:name="com.myproject.BackButton" />
</intent-filter>
</receiver>
public class InputReceive extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
String action = arg1.getAction();
if(action.equals("com.myproject.BackButton")){
back();
}
}
private void back(){
Log.e("wwq", "back");
}
}
When I run command in cmd
adb shell am broadcast -a com.myproject.BackButton
No log such as ‘back’ appear in logcat. Receiver no response.
Log is below:
12-12 16:33:05.431: W/ActivityManager(98): Timeout of broadcast BroadcastRecord{415fcd58 com.android.server.action.NETWORK_STATS_POLL} - receiver=android.app.LoadedApk$ReceiverDispatcher$InnerReceiver@4135ff18, started 10051ms ago
12-12 16:33:05.431: W/ActivityManager(98): Receiver during timeout: BroadcastFilter{41360160 ReceiverList{413600e8 98 system/1000 local:4135ff18}}
12-12 16:33:15.609: W/ActivityManager(98): finishReceiver called but no pending broadcasts
This issue only happened on Android 4.0 emulator. Who knows that what changed about Broadcast receiver in Android 4.0. Thanks a lot.
After your application is installed, the user need to launch an activity of yours manually before any of your
BroadcastReceiverswill have an effect, as of Android 3.1.Also, note that it is
android:enabled, notandroid.enabled.