0

我有一个在 20:00 运行的 AlarmManager,但当我单击修复它的按钮时也会运行。我只希望在 20:00 运行

Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 20);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
AlarmManager a = (AlarmManager)getSystemService(ALARM_SERVICE);
a.setRepeating(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),AlarmManager.INTERVAL_DAY,p);
4

1 回答 1

1

将以下代码放入您的代码中以在特定时间重复警报

    if(System.currentTimeMillis() <= c.getTimeInMillis()){

        AlarmManager a = (AlarmManager)getSystemService(ALARM_SERVICE);
        a.setRepeating(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),AlarmManager.INTERVAL_DAY,p);

    }

我希望它可以帮助你...

于 2014-01-08T05:28:43.550 回答