[英]Broadcast receiver not work on Android4.0 emulator
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 当我在cmd中运行命令时
adb shell am broadcast -a com.myproject.BackButton
No log such as 'back' appear in logcat. 在logcat中没有出现诸如'back'之类的日志。 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. 此问题仅发生在Android 4.0模拟器上。 Who knows that what changed about Broadcast receiver in Android 4.0. 谁知道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 BroadcastReceivers
will have an effect, as of Android 3.1. 安装应用程序后,用户需要在任何BroadcastReceivers
生效之前手动启动您的活动,从Android 3.1开始。
Also, note that it is android:enabled
, not android.enabled
. 另外,请注意它是android:enabled
,而不是android.enabled
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.