2014-09-10 61 views
2

我累了查找有关报警的具体日子,总是天天跑恳求谁可以帮我 并使用这些代码,这个是什么错误,运行每所以我发送dayOfWeek = 1;但每天跑报警在特定日子不是每天例如重复(周日,周二,周五)

public void setAlarm(int dayOfWeek) { 
    Toast.makeText(getApplicationContext(), dayOfWeek+","+h+","+m, 22222).show(); 
    cal1.set(Calendar.DAY_OF_WEEK, dayOfWeek); 
    cal1.set(Calendar.HOUR, 11); 
     cal1.set(Calendar.MINUTE, 0); 
     cal1.set(Calendar.SECOND, 0); 
     cal1.set(Calendar.MILLISECOND, 0); 
     Intent intent = new Intent(this, RemmemberActivity.class); 
     PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0, 
       intent, 0); 
     pendingIntent = PendingIntent.getActivity(this, 12345, 
       intent, PendingIntent.FLAG_UPDATE_CURRENT); 

      Long alarmTime = cal1.getTimeInMillis(); 
      am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE); 
     am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,24 * 60 * 60 * 1000 , pendingIntent); 
} 

回答

0

什么我可以为您设置报警每24小时重复该行快速浏览一下之后,会后:

am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,24 * 60 * 60 * 1000 , pendingIntent); 

dayOfWeek只用于当它熄灭第一次。

如果您有一个警报应该在同一时间每周关闭三次,请制作三个一周重复一次的警报。

am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, 7 * 24 * 60 * 60 * 1000 , pendingIntent); 
+0

确定,但我没有固定3天(太阳,周二,周五),可能是三个不同天根据复选框选择像一个(周一,周三,周六) – 2014-09-14 06:51:32

+0

好吧,我用这条线和每周六罚款am.setRepeating(AlarmManager.RTC_WAKEUP,alarmTime,7 * 24 * 60 * 60 * 1000,pendingIntent);但怎么可以设置每个星期天 – 2014-09-14 07:41:03

+0

谢谢你的帮助:) :) – 2014-09-14 08:32:49

0

最后,如果设置为(太阳,土族,星期五),你必须创建 这三天下面的代码设定的报警三个报警每个星期天和发送一个dayOfWeek = 1这个正确的解决方案; 重要注意每个创建的某一天运行必须在每个INTNET变更请求的代码(12345) 例如

public void setAlarm_sun(int dayOfWeek) { 
    cal1.set(Calendar.DAY_OF_WEEK, dayOfWeek); 
    Toast.makeText(getApplicationContext(), "sun "+cal1.get(Calendar.DAY_OF_WEEK), 222).show(); 

    Toast.makeText(getApplicationContext(), "Finsh", 222).show(); 

     Intent intent = new Intent(this, SecActivity.class); 
     PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0, 
       intent, 0); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 12345, 
       intent, PendingIntent.FLAG_UPDATE_CURRENT); 

     Long alarmTime = cal1.getTimeInMillis(); 
     AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE); 

     // am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,7* 24 * 60 * 60 * 1000 , pendingIntent); 
     am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,7* 24 * 60 * 60 * 1000 , pendingIntent); 

} 
相关问题