我的应用程序根据两组警报,开始时间和停止时间两次触发意图。我现在正在尝试对此进行扩展,以便可以在多天内指定设置警报,并可选择重复。
我在目标设备上的GCM中收到了8个整数值,repeat = 1,sun = 1,mon = 1等...如果选择了日期或重复,则其值为1.
如何在特定日期重复闹铃?
我可以将收到的值,0111110作为所有工作日例如...然后遍历它们并创建警报,其值为1 ??
我不知道如何构建这个,有人可以建议吗?
感谢。
答案 0 :(得分:0)
让它工作,使用以下...也许其他人会发现这个有用的
int[] daysOfWeek = new int[7];
int[] daysOfWeekValue = new int[7];
//parce from GCM values recieved
final int sunday = Integer.parseInt(sun);
daysOfWeek[0] = sunday;
final int monday = Integer.parseInt(mon);
daysOfWeek[1] = monday;
final int tuesday = Integer.parseInt(tue);
daysOfWeek[2] = tuesday;
final int wednesday = Integer.parseInt(wed);
daysOfWeek[3] = wednesday;
final int thursday = Integer.parseInt(thu);
daysOfWeek[4] = thursday;
final int friday = Integer.parseInt(fri);
daysOfWeek[5] = friday;
final int saturday = Integer.parseInt(sat);
daysOfWeek[6] = saturday;
final int repeating = Integer.parseInt(repeat);
daysOfWeekValue[0]=1;
daysOfWeekValue[1]=2;
daysOfWeekValue[2]=3;
daysOfWeekValue[3]=4;
daysOfWeekValue[4]=5;
daysOfWeekValue[5]=6;
daysOfWeekValue[6]=7;
for (int i=0; i<daysOfWeek.length; i++)
{
if(daysOfWeek[i]==1){
Log.i(TAG, "Set alarm on day: " + daysOfWeekValue[i]);
final Calendar calNow = Calendar.getInstance();
final Calendar calSet = (Calendar) calNow.clone();
calSet.set(Calendar.DAY_OF_WEEK, daysOfWeekValue[i]);// 1 for sunday, 2 for monday etc
calSet.set(Calendar.HOUR_OF_DAY, starthour);
calSet.set(Calendar.MINUTE, startmin);
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);
.....