【问题标题】:Set excact alarm repeating for API19 + [duplicate]为 API 19 + [复制] 设置精确的警报重复
【发布时间】:2016-09-23 13:09:00
【问题描述】:

我一直在研究 API 19 及更高版本的精确重复警报,我发现所有的警报重复都与 API 19 不精确。我想知道如何处理 API 19 的警报重复部分和以上。

我发现了这个:

您需要手动处理“重复”部分。

取自这里:How to set an exact repeating alarm on API 19 (kitkat)?

如何手动处理“重复”部分?

【问题讨论】:

  • 简单地说:时间到了,你的闹钟响了。正是在这个时候,你必须启动下一个闹钟。在您收到警报的 BroadcastReceiver 中,您必须开始下一个。
  • 每当它触发时再次设置确切的警报,有点像这里显示的:stackoverflow.com/questions/28269752/…
  • @MikeM。谢谢:)

标签: android alarmmanager android-4.4-kitkat


【解决方案1】:

使用这个:

public void scheduleAlarm() {
        Long time = new GregorianCalendar().getTimeInMillis()+1000 * 60 * 60 * 24;// current time + 24 Hrs
        Intent intent = new Intent(this, AlarmReceiver.class);
        PendingIntent intentAlarm  = PendingIntent.getBroadcast(this, 0, intent, 0);
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 1000 * 60 * 60 * 24, intentAlarm);// 24 Hrs
        Toast.makeText(this, "Alarm Scheduled for 24 Hrs", Toast.LENGTH_LONG).show();
    }

【讨论】:

  • setRepeating() 不再与 API 19 完全相同
猜你喜欢
  • 2015-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多