我想做一個重複的警報通知,在一天的特定時間內觸發。我發出的重複報警很好地發出了警報,但有時在設定的時間內關閉。例如,我在上午6點設置了鬧鐘,但在第二天第一次觸發後,它開始於上午6點15分,所以我想知道它們是否是更準確的鬧鐘設置方式?如何使重複報警更準確?
這是我的用於我的重複報警
Calendar calendar_dog= Calendar.getInstance();
calendar_dog.set(Calendar.HOUR_OF_DAY,7);
calendar_dog.set(Calendar.MINUTE,0);
calendar_dog.set(Calendar.SECOND,0);
Intent intent= new Intent(getApplicationContext(), notify_dog.class);
PendingIntent dog_intent=PendingIntent.getBroadcast(getApplicationContext(),100,intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager dog_alarm =(AlarmManager)getApplicationContext().getSystemService(ALARM_SERVICE);
dog_alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP,calendar_dog.getTimeInMillis(),AlarmManager.INTERVAL_DAY,dog_intent);
和我reciever
NotificationManager notify_dog=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent dog_intent= new Intent(context, HomeActivity.class);
dog_intent.setFlags(dog_intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent dog_pending=PendingIntent.getActivity(context,100,dog_intent,PendingIntent.FLAG_UPDATE_CURRENT);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder dog_build= new NotificationCompat.Builder(context).setContentIntent(dog_pending).
setSmallIcon(R.drawable.pet)
.setContentTitle("Pet Guide 101")
.setContentText("have you feed your Dog?")
.setSound(alarmSound)
.setAutoCancel(true);
notify_dog.notify(100,dog_build.build());
哦確定生病試試吧謝謝你.. –
@ tyreklGana,一個沒有工作的呢?如果是,請檢查我的解決方案是否已接受。 –