设置Alarm Manager停止的时间(Android)

时间:2015-07-04 20:59:16

标签: java android alarmmanager alarm

我有一个声音计划在每天晚上9点使用android中的警报管理器类播放。如何设置停止时间(例如,从下午2点开始,在晚上11点停止)?

    void playAudio() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 21);
    AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent objIntent = new Intent(this, Sound.class);
    PendingIntent alarmIntent = PendingIntent
            .getService(getApplicationContext(), 0, objIntent,
                    PendingIntent.FLAG_ONE_SHOT);
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, alarmIntent);
}

0 个答案:

没有答案