0

我在 9:00 和 21:00 有两个 AlarmManager,但只运行第二个警报。

    ////////9:00am/////////
    Intent aviso = new Intent(FijarAlerta.this,Servicio.class);
    PendingIntent pi = PendingIntent.getService(FijarAlerta.this, 0, aviso, PendingIntent.FLAG_UPDATE_CURRENT);
           //set the hour
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 9);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pi);

第二次报警

////////21:00pm//////////
    Intent avisopm = new Intent(FijarAlerta.this,Servicio.class);
    PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 0, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);
                 //set the hour
    Calendar calpm = Calendar.getInstance();
    calpm.set(Calendar.HOUR_OF_DAY, 21);
    calpm.set(Calendar.MINUTE, 0);
    calpm.set(Calendar.SECOND, 0);
    AlarmManager ampm = (AlarmManager)getSystemService(ALARM_SERVICE);
    ampm.setRepeating(AlarmManager.RTC_WAKEUP,calpm.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pipm);
4

2 回答 2

1

在每种情况下,调用的第二个参数PendingIntent.getService()应该是不同的数字。例如:

PendingIntent pi = PendingIntent.getService(FijarAlerta.this, 111, aviso,       PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 222, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);

目前,第二个 pendingIntent 只是覆盖了第一个

于 2013-01-28T10:53:36.900 回答
0

只需更换第二条报警线:

PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 0, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);

低于一个

PendingIntent pipm = PendingIntent.getService(FijarAlerta.this, 1, avisopm, PendingIntent.FLAG_UPDATE_CURRENT);

现在,如果您没有成功,请尝试让我发表评论。

享受编码。:)

于 2013-01-28T11:22:37.190 回答