我在注册广播接收器时遇到问题。
当我使用 registerReceiver 注册它时它可以工作:
registerReceiver(new NotifReceiver(), new IntentFilter(NotifReceiver.POST_NOTIF));
但不适用于 AndroidManifest.xml :
<receiver
android:name=".receiver.NotifReceiver"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name=".receiver.NotifReceiver.POST_NOTIF" />
</intent-filter>
</receiver>
NotifReceiver.java:
public class NotifReceiver extends BroadcastReceiver {
public static final String POST_NOTIF = "POST_NOTIF";
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(POST_NOTIF)) {
Log.d("debug", "action received");
}
}
}