因此,我一直在研究藥物攝入應用程序,我需要在本地提醒用戶(無需互聯(lián)網(wǎng)/推送通知)有關服用藥物的信息。我正在為此使用Android警報管理器。下面是代碼注釋:我正在嘗試為特定日期安排警報:“ 2018年7月13日,下午3點30分”。我安排并等待,但是提醒未觸發(fā)(因此未廣播),但是如果我使用AlarmManager.ELAPSED_REALTIME_WAKEUP并定義了毫秒數(shù),則會觸發(fā)(但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); }`
2 回答

叮當貓咪
TA貢獻1776條經(jīng)驗 獲得超12個贊
如果設備處于打ze模式,則不會觸發(fā)警報。也可以使用setAndAllowWhileIdle
或setExactAndAllowWhileIdle
在打ze模式下觸發(fā)警報。
來自Android Doc。
網(wǎng)絡訪問已暫停。
系統(tǒng)將忽略喚醒鎖。
標準AlarmManager警報(包括
setExact()
和setWindow()
)被推遲到下一個維護窗口。如果您需要設置在打ze時觸發(fā)的警報,請使用setAndAllowWhileIdle()
或setExactAndAllowWhileIdle()
。使用setAlarmClock()設置的警報將繼續(xù)正常觸發(fā)-在這些警報觸發(fā)之前,系統(tǒng)會立即退出Doze。
系統(tǒng)不執(zhí)行Wi-Fi掃描。
系統(tǒng)不允許運行同步適配器。系統(tǒng)不允許JobScheduler運行。
添加回答
舉報
0/150
提交
取消