我有一个声音计划在每天晚上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);
}