Unable to set retry on boot

I received a notice at 10:30 pm. But when my device turns off at 10:30 pm, and then after I turned on the device at 11:00 pm, I did not receive a pending notification. Therefore, I do not understand what the problem is. Any help would be appreciated.

Here is my code in action when creating.

Intent alarmIntent = new Intent(CH_Dashboard.this, TimeAlarmEvening.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(CH_Dashboard.this, 0, alarmIntent, 0); AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Calendar firingCal = Calendar.getInstance(); Calendar currentCal = Calendar.getInstance(); firingCal.set(Calendar.HOUR, 10); firingCal.set(Calendar.MINUTE, 30); firingCal.set(Calendar.SECOND, 0); firingCal.set(Calendar.AM_PM,Calendar.PM); long intendedTime = firingCal.getTimeInMillis(); long currentTime = currentCal.getTimeInMillis(); if(intendedTime >= currentTime) { manager.setRepeating(AlarmManager.RTC, intendedTime, AlarmManager.INTERVAL_DAY, pendingIntent); } else { firingCal.add(Calendar.DAY_OF_MONTH, 1); intendedTime = firingCal.getTimeInMillis(); manager.setRepeating(AlarmManager.RTC, intendedTime, AlarmManager.INTERVAL_DAY, pendingIntent); } 

My recipient code is here and successfully receives a notification when the device is turned on.

  Intent notificationIntent = new Intent(context, CH_Dashboard.class); notificationIntent.putExtra("fromNotification","notify"); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(CH_Dashboard.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setAutoCancel(true); Notification notification = builder.setContentTitle("Demo App Notification") .setContentText("New Notification From Demo App..") .setTicker("New Message Alert!") .setSmallIcon(R.mipmap.ic_launcher) .setContentIntent(pendingIntent).build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); 

here is my download receiver code.

  if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { Intent alarmIntent = new Intent(context, TimeAlarmEvening.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Calendar firingCal = Calendar.getInstance(); Calendar currentCal = Calendar.getInstance(); firingCal.set(Calendar.HOUR, 10); firingCal.set(Calendar.MINUTE, 30); firingCal.set(Calendar.SECOND, 0); firingCal.set(Calendar.AM_PM,Calendar.PM); long intendedTime = firingCal.getTimeInMillis(); long currentTime = currentCal.getTimeInMillis(); if(intendedTime >= currentTime) { manager.setInexactRepeating(AlarmManager.RTC, intendedTime, AlarmManager.INTERVAL_DAY, pendingIntent); } else { firingCal.add(Calendar.DAY_OF_MONTH, 1); intendedTime = firingCal.getTimeInMillis(); manager.setInexactRepeating(AlarmManager.RTC, intendedTime, AlarmManager.INTERVAL_DAY, pendingIntent); } } 

And the last one in the manifest, I announced the recipient.

  <receiver android:name=".model.AutoStart" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver> <receiver android:name=".TimeAlarmEvening"> <intent-filter> <action android:name="android.media.action.DISPLAY_NOTIFICATION_EVENING" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver> 
+7
android android-pendingintent alarmmanager
source share
2 answers

I decided that day, but forgot to answer here. I made some changes to the manifest file. Just remove the default line category in both intent filters and work.

  <receiver android:name=".model.AutoStart" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <receiver android:name=".TimeAlarmEvening"> <intent-filter> <action android:name="android.media.action.DISPLAY_NOTIFICATION_EVENING" /> </intent-filter> </receiver> 
+4
source share

I do not write all the code for you. But I can show you where you can apply your logic.

-> First, find a way to track yourself that is missing, for example, by tracking the status of an event in the database.

-> Then configure a BOOT_COMPLETED BroadcastReceiver to find when the phone is rebooted. There, plan any alarms that are still in the future, and decide what to do with alarms that occurred in the past but were missed (for example, raise an alert by indicating missed events).

- One way to do this is to listen to the phone shutdown event:

 <action android:name="android.intent.action.ACTION_SHUTDOWN" /> 

and before the device turns off, save the time off.

Then listen to the device boot:

 <action android:name="android.intent.action.BOOT_COMPLETED" /> 

and write your own logic that determines which alarms will be triggered during this outage, and immediately start these alarms using the AlarmManager.

0
source share

All Articles