在Android中重复本地通知 [英] Repeating Local Notification in android
问题描述
我正在尝试发出通知,安装了应用程序后,它会在每月的第1个月自动设置警报/通知,并在单击该通知后会打开该应用程序的特定活动
I am trying to make a notification, Whever app is installed, it automatically set alarm/notification every 1st of month and upon clicking that notification it opens a specific activity of the application
这是我的警报管理器代码
Here is my code for alarm manager
// 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中。我该如何设置它每月重复一次?
My problem is, i want to set it as a repeating notification, each month on 1st. The alarm code, I have it in my mainActivity. How can i set it that it will repeat each month
推荐答案
安排一个重复警报可以通过setRepeating()of AlarmManager()
public void setRepeating(int类型,长触发器,行长,间隔长,密执业意图)
希望您可以通过检查哪个月份并修改
INTERVAL_DAY * 28 $ c $来实现目标c>或
INTERVAL_DAY * 30
或INTERVAL_DAY * 31
通过设置标志和所有其他标志。
Hope you can achieve your goal by checking which month is and modify the
INTERVAL_DAY *28
OrINTERVAL_DAY*30
ORINTERVAL_DAY*31
by setting flags and all that.
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY*30, sender);
这篇关于在Android中重复本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!