标签:broadcastreceiver action 接收不到 intentfilt
<receiver
android:name=".MyReceiver" android:enabled="true">
<intent-filter>
<action android:name="myAction" />
</intent-filter>
</receiver>
@Override
protected void onStart() {
super.onStart();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("myAction");
registerReceiver(myReceiver, intentFilter);
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(myReceiver);
}
Intent intent = new Intent();
intent.setAction("myAction");
sendBroadcast(intent);
如果没有添加IntentFilter的Action,那么BroadcastReceiver将的onReceive(Context context, Intent intent)将收不到通知,除非你在发送的时候指明的具体的Class:
Intent intent = new Intent(MyActivity.this,MyReceiver.class);
sendBroadcast(intent);
标签:broadcastreceiver action 接收不到 intentfilt
原文地址:http://blog.csdn.net/deviltsw/article/details/44776281