我有以下代码,它在指定时间每天启动一项服务。有人知道如何从周一到周五开始吗?
Calendar startTime = Calendar.GetInstance(Locale.Default);
startTime.Set(CalendarField.HourOfDay, 10);
startTime.Set(CalendarField.Minute, 00);
startTime.Set(CalendarField.Second, 00);
AlarmManager mgr = (AlarmManager)context.GetSystemService(Context.AlarmService );
Intent i = new Intent(context, typeof(myService));
PendingIntent pi = PendingIntent.GetService(context, 0, i, 0);
mgr.SetRepeating(AlarmType.Rtc , startTime.TimeInMillis , 24*60*60*1000 , pi);
答案 0 :(得分:0)
我想你想使用CalendarField.DayOfWeek。见:https://developer.android.com/reference/java/text/DateFormat.Field.html#DAY_OF_WEEK。所以你想要做这样的事情:
startTime.Set(CalendarField.DayOfWeek, Calendar.Monday);
startTime.Set(CalendarField.DayOfWeek, Calendar.Tuesday);
startTime.Set(CalendarField.DayOfWeek, Calendar.Wednesday);
startTime.Set(CalendarField.DayOfWeek, Calendar.Thursday);
startTime.Set(CalendarField.DayOfWeek, Calendar.Friday);