我正在尝试发出通知,安装了Whever应用程序,它每月1日自动设置警报/通知,点击该通知后会打开应用程序的特定活动
这是我的警报管理器代码
// get a Calendar object with current time
Calendar cal = Calendar.getInstance();
// add 5 minutes to the calendar object
cal.add(Calendar.MINUTE, 5);
Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra(MESSAGE);
PendingIntent sender = PendingIntent.getBroadcast(this, 10, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Get the AlarmManager service
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
我做了警报课
@Override
public void onReceive(Context context, Intent intent)
{
try {
Intent newIntent = new Intent(context, Appointment.class);
context.startActivity(newIntent);
}
catch (Exception e)
{
Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
我的问题是,我希望每月1日将其设置为重复通知。警报代码,我在mainActivity中有它。我如何设置它将每月重复
答案 0 :(得分:2)
Schedule a repeating alarm can be achieved by setRepeating() of AlarmManager()
public void setRepeating (int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)
希望您可以通过查看哪个月来实现目标,并通过设置标记和所有内容来修改
INTERVAL_DAY *28
或INTERVAL_DAY*30
或INTERVAL_DAY*31
。
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY*30, sender);