如何在任何一天/时间重复报警?

时间:2017-11-05 15:16:59

标签: java android broadcastreceiver alarmmanager

使用广播接收器,我怎样才能让闹钟管理员在日/日/时间内重复一次?

public void startAlert(String time, String title) {
    long timeInMillis = Long.decode(time);
    intent = new Intent(this, AlarmReceiver.class);
    intent.putExtra("myTitle", title);
    alarmmanager = (AlarmManager) getSystemService(ALARM_SERVICE);
    pendingIntent = PendingIntent.getBroadcast(this, (int) Long.parseLong(time), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmmanager.set(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
}

2 个答案:

答案 0 :(得分:0)

使用setRepeating代替set 这是正确的语法 -

alarmmanager.setRepeating(AlarmManager.RTC_WAKEUP,
        startUpTime, AlarmManager.INTERVAL_DAY, pendingIntent);

答案 1 :(得分:0)

我认为你可以使用setRepeating和另一个question的自定义日期。

  

alarmmanager.setRepeating(AlarmManager.RTC_WAKEUP,           startUpTime,AlarmManager.INTERVAL_DAY,pendingIntent);