我注册了我计划在给定时间执行的警报,根据计划列表的大小,它可以是许多警报。但是我有两个问题我还不清楚:
1) 我如何在操作系统中查询我注册的 Pending Intents?我需要这个进行测试。我想要的伪代码是这样的:
List<PendingIntent> intentsInOS = context.getAllPendingIntentsOfType(AppConstants.INTENT_ALARM_SCHEDULE));
2)查看我创建的未决意图,我提供了一个操作和额外的数据(计划 ID)。
private Intent getSchedeuleIntent(Integer id) {
    Intent intent = new Intent(AppConstants.INTENT_ALARM_SCHEDULE);
    intent.putExtra(AppConstants.INTENT_ALARM_SCHEDULE_EXTRA, id);
    return intent;
}
但是我们也说intent有FLAG_CANCEL_CURRENT。它会以相同的操作取消所有待处理的意图,还是必须同时执行相同的操作和额外的数据?
PendingIntent pendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, getSchedeuleIntent(schedule.id), PendingIntent.FLAG_CANCEL_CURRENT);
我的代码
@Override
public void run() {
    List<ScheduledLocation> schedules = dbManager.getScheduledLocations();
    if(schedules == null || schedules.isEmpty()){
        return;
    }
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    //alarmManager.
    // we need to get the number of milliseconds from current time till next hour:minute the next day.
    for(ScheduledLocation schedule : schedules){
        long triggerAtMillis = DateUtils.millisecondsBetweenNowAndNext(now, schedule.hour, schedule.minute, schedule.day);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, getSchedeuleIntent(schedule.id), PendingIntent.FLAG_CANCEL_CURRENT);
        alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtMillis, MILLISECONDS_IN_WEEK, pendingIntent);
    }
    // List<PendingIntent> intentsInOS = context.getAllPendingIntentsOfType(AppConstants.INTENT_ALARM_SCHEDULE));
}
private Intent getSchedeuleIntent(Integer id) {
    Intent intent = new Intent(AppConstants.INTENT_ALARM_SCHEDULE);
    intent.putExtra(AppConstants.INTENT_ALARM_SCHEDULE_EXTRA, id);
    return intent;
}