[英]alarm repeating at specific day not every day example ( Sunday, Tuesday , Friday)
I am tired to find specific day about alarm and always run every day pleas who can help me AND use these code what error about this ,run every so i send dayOfWeek=1; 我厌倦了寻找有关警报的特定日期,并且每天都在运行请谁来帮助我并使用这些代码的错误吗,请每天运行,以便我发送dayOfWeek = 1; but run every day
但每天跑
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);
}
After what I can see after a quick look you set alarm to repeat every 24 hours on this row: 经过快速浏览后,我看到您将警报设置为每24小时在此行重复一次:
am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,24 * 60 * 60 * 1000 , pendingIntent);
Your dayOfWeek
is only used for when it will go off the first time. 您的
dayOfWeek
仅在第一次关闭时使用。
If you have an alarm that should go off three times a week on the same time, make three alarms that repeat once a week. 如果您有一个警报,应该每周一次在同一时间响起三次,请制作三个警报,每个星期重复一次。
am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, 7 * 24 * 60 * 60 * 1000 , pendingIntent);
finally this right solution if set as (sun,tus ,fri) you must create three alarm for these three day the following code set alarm every sunday and send dayOfWeek=1; 最后,如果将此正确的解决方案设置为(sun,tus,fri),则必须为这三天创建三个警报,以下代码在每个星期日设置警报并发送dayOfWeek = 1; important note every create a run at some day must change request code in every intnet (12345) in example
重要说明,示例中每次创建运行都必须在每个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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.