First sorry for my english. I have a list of alarms and I need to wake up the application with a notification in a specific time. I only put one alarm at a time. I put an alarm with the set function, it works, then I put the next alarm in the broadcast but it doesn't wake up at time. Why? The milliseconds are diferent and correct but the alarm doesn't work.
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);
}
Thank you