所以我设置了一个触发意图的警报。我还有一个广播监听器,它有一个意图过滤器来捕捉该意图,但由于某种原因它不起作用。我不确定问题出在哪里(发送或接收或两者兼而有之)。
发送代码:
Intent reminderIntent = new Intent();
reminderIntent.setAction(INTENT_ACTION_ALARM); //INTENT_ACTION_ALARM is String "intent_myaction_alarm"
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, reminderIntent, 0);
Calendar time = Calendar.getInstance();
time.setTimeInMillis(System.currentTimeMillis());
alarmManager.set(AlarmManager.RTC, time.getTimeInMillis(), pendingIntent);
接收代码:
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(INTENT_ACTION_ALARM);
alarmReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// DO SOMETHING
}
};
context.registerReceiver(alarmReceiver, intentFilter);