2013-06-03 3 views
1

영어로 죄송합니다. 나는 경보 목록을 가지고 있으며, 특정 시간에 알림으로 응용 프로그램을 깨울 필요가 있습니다. 한 번에 하나의 알람 만 울립니다. 설정 기능으로 알람을 울리면 작동합니다. 그런 다음 브로드 캐스트에 다음 알람을 넣지 만 시간에는 깨어나지 않습니다. 왜? 밀리 초는 다르지만 정확하지만 경보가 작동하지 않습니다.AlarmManager Android 세트가 두 번째로 작동하지 않습니다.

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); 
} 

당신에게

+0

어디'(참)'updateAlarm의 코드? –

+0

나는 데이터베이스의 다음 알람을 참조한 다음 setNextAlarm을 호출하여 새 것을 넣습니다. – user1852854

답변

0

alarm.set (AlarmManager.RTC_WAKEUP, milisegundos, pintent를) 감사; 단지 사용자 setRepeating 기능은 지연 간격 여기

를 지정 한 번 알람을 설정할 것입니다 완벽한 솔루션

Alarm Manager Example

+0

감사합니다. 그것은 작동합니다! – user1852854

+0

이 문제가 있습니다. 그것은 작동하지만 응용 프로그램이 배경에있는 경우 알람이 작동하지 않습니다. 문제가 어디에 있습니까? 고맙습니다! – user1852854

관련 문제