【问题标题】:Time-based notification in OreoOreo 中基于时间的通知
【发布时间】:2018-01-20 12:27:54
【问题描述】:

我正在开发一个任务调度应用程序,它可以在某个时间提醒我某项任务。我曾经用getSystemService(AlarmManager.class).set(RTC_WAKEUP, millis, pendingIntent); 来实现这个。然后IntentService 稍后启动并显示通知。

但在 Android Oreo 中,我的 IntentService 根本不会被调用。我注意到关于Background Execution Limits 以及如何从AlarmManager 迁移到JobScheduler 的大量讨论,但没有人提到JobScheduler 如何基于RTC 开始工作。

我的IntentService 除了显示通知外,所做的无非是将任务设置为“已通知”或“完成”,我认为这与@987654330 通过网络同步大量数据等繁重任务无法相比@ 被引入。

在 Android Oreo 中实现基于时间的通知的最佳做法是什么?

【问题讨论】:

  • 建议使用广播接收器。 stackoverflow.com/questions/45815899/…
  • 使用 firebase 作业调度器
  • @notTdar 您能否提供有关如何使用 Firebase JobDispatcher 来安排 RTC 任务的更多信息?
  • Jobs 会自动唤醒您的设备,但如果您想知道准确的时间,请使用 setAlarmClock 和 setExactWhileInIdle

标签: android android-alarms android-8.0-oreo android-jobscheduler


【解决方案1】:

我正在采用@balu-sangem 的解决方案:

  • PendingIntent.getService() 替换为 PendingIntent.getBroadcast()
  • IntentService 替换为BroadcastReceiver

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    相关资源
    最近更新 更多