2016-11-15 5 views
0

특정 지역의 알림을 예약하려고하는데 AlarmManager를 사용하여 알림을 예약하고 있습니다. 불행히도 그것은 미래의 시대에는 효과가 없습니다. 어떤 아이디어?AlarmManager가 알림을 전달하지 않습니다.

이 알람이

private long computeDelay(int day){ 

    long currentSystemTime = System.currentTimeMillis(); 

    Calendar scheduleTime = Calendar.getInstance(); 

    // used to compute number of hours and mins 
    int currentDay = scheduleTime.get(Calendar.DAY_OF_MONTH); 
    scheduleTime.set(Calendar.DAY_OF_MONTH, currentDay + day); 
    scheduleTime.set(Calendar.HOUR, 7); 
    scheduleTime.set(Calendar.MINUTE, 0); 
    scheduleTime.set(Calendar.SECOND, 0); 
    scheduleTime.set(Calendar.AM_PM, Calendar.PM); 

    return scheduleTime.getTimeInMillis(); 
} 

를 트리거해야 할 때 나는 시간을 계산 내가 알람을 예약하는 방법이이 방법이다.

private void scheduleNotification(Notification notification, long time) { 
    Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION"); 

    notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, 1); 
    notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification); 
    notificationIntent.addCategory("android.intent.category.DEFAULT"); 

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
    alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent); 
} 

컨텍스트는 응용 프로그램 (즉, getApplication())입니다.

감사합니다.

+2

이미지를 제거하고 코드를 붙여 넣습니다. 이미지를 검색 할 수 없습니다. – 323go

+1

분류 됨! 미안합니다! –

답변

0

문제는 내가 PendingIntent를 얻는 방법과 관련이 있습니다.

알람 일정 메서드를 여러 번 호출했으며 요청 코드가 항상 0 이었기 때문에 마지막 알람 만 예약했습니다. 나는 지금 각 경보 계획에게 유일한 요구 부호를주고있다 그리고 그것은 잘 작동하는 것처럼 보인다.