私は私を取得しようとしています毎日通知サービスが正常に動作していますが、問題が残っています。Androidの通知アプリケーションの起動時にトリガする
私は将来で一日の特定の時間に通知を受け取る必要がありますが、私は間違っている
if (time_that_i_set_for_notification < current_time_of_the_day) notification triggers at the boot of my app
は、その状態で、通知が唯一の翌日をトリガーする必要があるためということに気づきました、私はアプリを起動する瞬間ではありません。ここで
は、作業の事を得るために私の試みです:
私はのonCreate()メソッド、私のMainActivityでこれを呼び出す:私はif(calendar.getTime().compareTo(new Date()) < 0) calendar.add(Calendar.DAY_OF_MONTH, 1);
を追加すると、私は結果を達成しただろうと思っ
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);
}
必要だった。
ありがとうございました。
完璧!私はこの問題を解決しました!非常に良い答えはありがとう! – Claff