在Android的一周报警设置重复天

编程入门 行业动态 更新时间:2024-10-23 21:34:54
本文介绍了在Android的一周报警设置重复天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人可以提供良好的逻辑的一周报警设定重复的日子吗?我已经通过每周进行报警

Can somebody give good logic for set repeat days of week alarm? I have done weekly Alarm by using

alarmCalendar.set(Calendar.HOUR, AlarmHrsInInt); alarmCalendar.set(Calendar.MINUTE, AlarmMinsInInt); alarmCalendar.set(Calendar.SECOND, 0); alarmCalendar.set(Calendar.AM_PM, amorpm); Long alarmTime = alarmCalendar.getTimeInMillis(); Intent intent = new Intent(Alarm.this, AlarmReciever.class); intent.putExtra("keyValue", key); PendingIntent pi = PendingIntent.getBroadcast(Alarm.this, key, intent, PendingIntent.FLAG_UPDATE_CURRENT); am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, 7*1440*60000 , pi);

在时间和报警触发后7天,它会自动触发在那个时候。

The alarm trigger on time and after 7 days it automatically triggers at that time.

但我的要求是我要选择天,而不是仅仅7天。

But my requirement is I want to choose days rather than just 7 days.

像每周一,周二,周四上午9点 - 报警应自动触发。我该如何去有关setRepeating这样做。

something like every Monday, Tuesday, Thursday at 9:00 AM - Alarm should trigger automatically. How do I go about doing this in setRepeating.

有人可以帮我这个?

谢谢!

推荐答案

这些问题谈论同样的事情,只要你想。这些问题的答案将是有益的:

These questions talk about the same thing as you want. Those answers will be helpful:

您只需要到指定的一天的开始,然后重复它每隔7天。有上给出的问题答案中指定的几个方面:

You just need to specify the day to start it and then repeat it every 7 days. There are few ways specified in answers on given questions:

How我可以使用报警经理周天重复报警?

Android在具体工作日通知熄灭直接

如何重复报警本周日在机器人

更新:

在你的评论说

如何设置triggerAtMillis部分setRepeating。比方说今天是星期二,我选择每周的周一,周三,周五。 - 做什么,我把周三

How to set the triggerAtMillis part in setRepeating. say for example today is Tuesday, I choose weekly Monday, Wednesday, Friday. - What do I put for Wednesday ?

我的理解是,如果今天是星期二,如何设置报警让说周三的重复,对不对?首先是你可以使用mulltiple的ID分别设置报警每一天。

What I understood that that if today is Tuesday, how to set alarm for lets say Wednesday repeating, right? First of all yes you can use mulltiple id's to set alarms for each day separately.

然后你可以添加 alarmCalendar.set(Calendar.DAY_OF_WEEK,周); 行现有的code。根据本周日(1-7),它重复的那一天。你可以将它传递给函数的参数。像:

Then you can add alarmCalendar.set(Calendar.DAY_OF_WEEK, week); line to your existing code. Based on the week day( from 1-7) it repeats for that day. You can pass it into a function as parameter. Like:

setAlarm(2); //set the alarm for this day of the week public void setAlarm(int dayOfWeek) { // Add this day of the week line to your existing code alarmCalendar.set(Calendar.DAY_OF_WEEK, dayOfWeek); alarmCalendar.set(Calendar.HOUR, AlarmHrsInInt); alarmCalendar.set(Calendar.MINUTE, AlarmMinsInInt); alarmCalendar.set(Calendar.SECOND, 0); alarmCalendar.set(Calendar.AM_PM, amorpm); Long alarmTime = alarmCalendar.getTimeInMillis(); //Also change the time to 24 hours. am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, 24 * 60 * 60 * 1000 , pi); }

我已经采取的例子从上面的问题之一。希望它更清楚了吧。

I've taken the example from one of above question. Hope its more clear now.

更多推荐

在Android的一周报警设置重复天

本文发布于:2023-11-27 05:15:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636748.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!