我有一个部分工作的报警管理器。它启动一个动作,我真正想要的是在稍后的指定时间停止此动作。课程如下。
public class MuteManagerClass {
private Context mContext;
private AlarmManager mAlarmManager;
public MuteManagerClass(Context context) {
mContext = context;
mAlarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
}
public void setAlarm(Calendar start, Calendar end, String card) {
Intent i = new Intent(mContext, MuteBroadcastReceiver.class);
i.putExtra("CARD", card);
i.putExtra("end", end.getTimeInMillis());
PendingIntent pi = PendingIntent.getBroadcast(mContext, (int) System.currentTimeMillis(), i, 0);
PendingIntent pendingIntent = PendingIntent.getService(mContext, 3, i, PendingIntent.FLAG_UPDATE_CURRENT);
mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, start.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pi);
//mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, start.getTimeInMillis(), 60000, pi);
}
}
显然,警报从启动日历对象开始。我希望警报启动的操作以结束日历对象结束。 当闹钟开始时,它会使手机静音,我希望它在结束日历对象期间返回正常模式。