我正在尝试发出通知,无论安装了应用程序,它都会每隔一个月自动设置一次警报/通知,并在单击该通知时打开应用程序的特定活动
这是我的警报管理器代码
// 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 中有它。我如何设置它每月重复一次