gpt4 book ai didi

android - 在android中每周重复一次闹钟

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:37:08 25 4
gpt4 key购买 nike

我正在尝试在我的应用程序中开发警报功能,该应用程序在用户指​​定的固定时间的一周内运行。这里的问题是我的调度程序运行一整天而不是在指定的一天运行。这是我为此编写的代码,请帮助解决此问题

Calendar calNow = Calendar.getInstance();
SimpleDateFormat simpDate;
simpDate = new SimpleDateFormat("kk:mm:ss");
if(in_Date==1)
{
calNow.set(Calendar.HOUR_OF_DAY, hourOfDay);
calNow.set(Calendar.MINUTE, minute);
calNow.set(Calendar.SECOND, 0);
calNow.set(Calendar.MILLISECOND, 0);
}
else if(in_Date==2)
{
calNow.set(Calendar.HOUR_OF_DAY, hourOfDay);
calNow.set(Calendar.MINUTE, minute);
calNow.set(Calendar.SECOND, 0);
calNow.set(Calendar.MILLISECOND, 0);
calNow.set(Calendar.DAY_OF_WEEK,in_SelectedDay);
}
etTime.setText(simpDate.format(calNow.getTime()));
Seconds=calNow.getTimeInMillis();

private void setAlarm(){

//etTime.setText(simpDate.format(calNow.getTime()));

Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);

if(in_Date==1)
{

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, Seconds,alarmManager.INTERVAL_DAY,pendingIntent);
}
else if(in_Date==2)
{

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, Seconds,1 * 60 * 60 * 1000,pendingIntent);
}

}

最佳答案

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, Seconds, AlarmManager.INTERVAL_DAY, pendingIntent);

在这一行中,您将开始时间设置为用户选择的日期,然后将间隔设置为 INTERVAL_DAY

您应该使用 INTERVAL_DAY * 7 来确保它每周重复一次:

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, Seconds, AlarmManager.INTERVAL_DAY * 7, pendingIntent);

关于android - 在android中每周重复一次闹钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16237382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com