通知来得太频繁而不是一天一次
Notification comes too frequent instead of once a day
我正在尝试构建一个每天同一时间(中午)发送通知的应用程序。但是,它每两个小时来一次。我做错了什么吗?
这是我设置闹钟时间的代码片段。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
findViewsById();
setDateTimeField();
today.set(Calendar.HOUR_OF_DAY, 12);
today.set(Calendar.MINUTE, 00);
today.set(Calendar.SECOND, 0);
Intent myIntent=new Intent(Main.this, MyReceiver.class);
PendingIntent pendingIntent=PendingIntent.getBroadcast(Main.this,0,myIntent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,today.getTimeInMillis(),24*60*60*1000,pendingIntent);
如有任何帮助,我们将不胜感激。代码有效,但出现得太频繁了
检查一下,
https://developer.android.com/training/scheduling/alarms.html
// Set the alarm to start at approximately 2:00 p.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 14);
// With setInexactRepeating(), you have to use one of the AlarmManager interval
// constants--in this case, AlarmManager.INTERVAL_DAY.
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent);
我正在尝试构建一个每天同一时间(中午)发送通知的应用程序。但是,它每两个小时来一次。我做错了什么吗? 这是我设置闹钟时间的代码片段。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
findViewsById();
setDateTimeField();
today.set(Calendar.HOUR_OF_DAY, 12);
today.set(Calendar.MINUTE, 00);
today.set(Calendar.SECOND, 0);
Intent myIntent=new Intent(Main.this, MyReceiver.class);
PendingIntent pendingIntent=PendingIntent.getBroadcast(Main.this,0,myIntent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,today.getTimeInMillis(),24*60*60*1000,pendingIntent);
如有任何帮助,我们将不胜感激。代码有效,但出现得太频繁了
检查一下, https://developer.android.com/training/scheduling/alarms.html
// Set the alarm to start at approximately 2:00 p.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 14);
// With setInexactRepeating(), you have to use one of the AlarmManager interval
// constants--in this case, AlarmManager.INTERVAL_DAY.
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent);