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())입니다.
감사합니다.
이미지를 제거하고 코드를 붙여 넣습니다. 이미지를 검색 할 수 없습니다. – 323go
분류 됨! 미안합니다! –