首先对不起我的英语。我有一个警报列表,我需要在特定时间通过通知唤醒应用程序。我一次只设置一个闹钟。我用设置功能设置了一个闹钟,它可以工作,然后我将下一个闹钟放在广播中,但它没有按时唤醒。为什么?毫秒不同且正确,但警报不起作用。
public static void setNextAlarma(long milisegundos){
Bundle extras = new Bundle();
extras.putString("mensaje", "message");
Intent i = new Intent(InfoApp.ALERT_MANAGER);
i.putExtras(extras);
PendingIntent pintent = PendingIntent.getBroadcast(InfoApp.miContexto, (int) milisegundos, i, 0);
if (milisegundos != 0){
InfoApp.miContexto.registerReceiver(AlertasBrCast, new IntentFilter(InfoApp.ALERT_MANAGER));
AlarmManager alarm = (AlarmManager)InfoApp.miContexto.getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, milisegundos, pintent);
}
else{
AlarmManager alarm = (AlarmManager)InfoApp.miContexto.getSystemService(Context.ALARM_SERVICE);
alarm.cancel(pintent);
}
}
public final static BroadcastReceiver AlertasBrCast = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String mensaje = "";
if (extras != null)
mensaje = extras.getString("mensaje");
generateNotification(context, mensaje, Calendario.class, null);
updateAlarm();
}
};
public void updateAlarm(){
// Consult the next alarm in the database
long fechaNuevaMilli = (Utilidades.strToDate(nuevaFecha,
InfoApp.formatoSQL)).getTime();
Utilidades.setNextAlarma(fechaNuevaMilli);
}
谢谢