且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

具有特定日期的 Android 闹钟设置

更新时间:2023-01-28 10:32:27

你应该调用public void setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation)(看这里) 重复警报.例如,你想在每天早上 9:00 发出警报,你可以这样做:

You should call public void setRepeating (int type, long triggerAtTime, long interval, PendingIntent operation)(see here) to repeat the alarm. For example, you want to fire the alarm on 9:00 am every day, you can do :

Calendar c=Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 9);
c.set(Calendar.MINUTE, 0);
setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), AlarmManager.INTERVAL_DAY,pendingIntent);

另外,在初始化 PendingIntent 时将最后一个参数设置为 0.

Also,set the last parameter to 0 when initilazing the PendingIntent.

PendingIntent pendingIntent = PendingIntent.getBroadcast(fridgeDetails.this, 
                        0, myIntent, 0);