내 일 알림 서비스가 제대로 작동하지만 문제가 생겼습니다.Android 시작 알림 응용 프로그램 시작시 트리거
난 단지 미래에 하루 의 특정 시간에 알림을받을 그러나 나는 잘못
if (time_that_i_set_for_notification < current_time_of_the_day) notification triggers at the boot of my app
그 상태로, 통지는 다음 날를 실행해야하기 때문에 것으로 나타났습니다 , 내가 앱을 실행하는 순간이 아닙니다.
여기 것들이 작동하게 내 시도이다 :
이내가 내 MainActivity에서 이것을 호출에서 onCreate() 메소드 :
private void scheduleNotification(int hour, int minute){
Intent notificationIntent = new Intent(this, NotificationReceiver.class);
notificationIntent.putExtra("notifId", notifId);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, notifId, notificationIntent, 0);
// Set the alarm to start at approximately at a time
DatePicker datePicker = new DatePicker(this);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
if(calendar.getTime().compareTo(new Date()) < 0) calendar.add(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 12);
AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
// With setInexactRepeating(), you have to use one of the AlarmManager interval
// constants--in this case, AlarmManager.INTERVAL_DAY.
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pendingIntent);
}
나는 if(calendar.getTime().compareTo(new Date()) < 0) calendar.add(Calendar.DAY_OF_MONTH, 1);
추가 나는 결과를 달성 한 것이라고 생각 내가 필요.
감사합니다. 좋은 하루 되세요. 이 도움이
if (calendar.getTimeInMillis() < System.currentTimeMillis())
calendar.setTimeInMillis(calendar.getTimeInMillis() + AlarmManager.INTERVAL_DAY);
희망 :
Perfect! 나는 그 문제를 해결했다! 아주 좋은 대답은 당신에게 감사합니다! – Claff