因此,我一直在研究药物摄入应用程序,我需要在本地提醒用户(无需互联网/推送通知)有关服用药物的信息。我正在为此使用Android警报管理器。下面是代码注释:我正在尝试为特定日期安排警报:“ 2018年7月13日,下午3点30分”。我安排并等待,但是提醒未触发(因此未广播),但是如果我使用AlarmManager.ELAPSED_REALTIME_WAKEUP并定义了毫秒数,则会触发(但AlarmManager.RTC_WAKEUP却不起作用)
AlarmManager manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent myIntent;
PendingIntent pendingIntent;
long reminderDateTimeInMilliseconds = 000;
myIntent = new Intent(this,MedicationScheduleBroadCastReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this,0,myIntent,PendingIntent.FLAG_UPDATE_CURRENT);
//TODO : Reminder the user to take medication on the 13th July 2018 at 15:30
Calendar calendarToSchedule = Calendar.getInstance();
calendarToSchedule.set(Calendar.YEAR, 2018);
calendarToSchedule.set(Calendar.MONTH, 07);
calendarToSchedule.set(Calendar.DAY_OF_MONTH, 13);
calendarToSchedule.set(Calendar.HOUR_OF_DAY, 15);
calendarToSchedule.set(Calendar.MINUTE, 30);
reminderDateTimeInMilliseconds = calendarToSchedule.getTimeInMillis();
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O){
manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, reminderDateTimeInMilliseconds, pendingIntent);
}
else{
manager.set(AlarmManager.RTC_WAKEUP, reminderDateTimeInMilliseconds, pendingIntent);
}
`
叮当猫咪
相关分类