亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

AlarmManager 在 Android 8.1.0 中不起作用

AlarmManager 在 Android 8.1.0 中不起作用

森欄 2022-11-02 17:15:27
我的要求設置Notification為特定時間,例如用戶生日或假期我正在使用AlarmManager使用廣播接收器來安排通知代碼工作正常6.0(即使應用程序被殺死,從最近的列表中刷卡)但不能正常工作Android 8.1.0(Mf:Oppo)閱讀了這個和這個以及許多答案,但沒有找到任何有用的任何想法如何解決這個問題這是我的代碼   AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);    //creating a new intent specifying the broadcast receiver\    Intent i = new Intent(this, HolidayBroadcast.class);    i.putExtra("eventName",islamicHoliday.getEventName());    i.putExtra("dateH", testTmp.getCalendar().getTimeInMillis());    i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);    //creating a pending intent using the intent    PendingIntent pi = PendingIntent.getBroadcast(this, new Random().nextInt(), i, PendingIntent.FLAG_UPDATE_CURRENT);    //setting alarm    if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.M) {        am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,getTimeInMillis(), pi);    }    else    {        am.setExact(AlarmManager.RTC_WAKEUP, getTimeInMillis(), pi);    }
查看完整描述

2 回答

?
鳳凰求蠱

TA貢獻1825條經驗 獲得超4個贊

您可以使用鏈接中提到的 workmanager。它支持所有 api 版本并且易于使用,因為它向后兼容 API 級別 14

https://developer.android.com/topic/libraries/architecture/workmanager

https://medium.com/androiddevelopers/introducing-workmanager-2083bcfc4712


查看完整回答
反對 回復 2022-11-02
?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

如果您的任務對時間要求很高,則不建議使用 WorkManager API,因為您的警報管理器無法正常工作,在 Android 8 上使用 AlarmManager.setexactandallowwhileidle(),設置準確時間并允許在應用程序被殺死時喚醒通知。



查看完整回答
反對 回復 2022-11-02
  • 2 回答
  • 0 關注
  • 348 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號