Fire notification at every 24 hours and at exact time of 8 AM

后端 未结 4 1011
再見小時候
再見小時候 2020-12-08 02:39

I am using AlarmManager() to fire notification and repeat it at every 24 hours.

My code is on onCreate() in Splash Activity which fires fi

4条回答
  •  借酒劲吻你
    2020-12-08 03:43

    // Retrieve a PendingIntent that will perform a broadcast
                Intent alarmIntent = new Intent(HomeContactActivity.this,
                        AlarmReceiver.class);
                pendingIntent = PendingIntent.getBroadcast(
                        HomeContactActivity.this, 0, alarmIntent, 0);
    
                AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    
                // Set the alarm to start at 10:00 AM
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(System.currentTimeMillis());
                calendar.set(Calendar.HOUR_OF_DAY, 10);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
    
    
    
    
                manager.setRepeating(AlarmManager.RTC_WAKEUP,
                        calendar.getTimeInMillis(), 86400000, // for repeating
                                                                // in every 24
                                                                // hours
                        pendingIntent);
    

提交回复
热议问题