Search code examples
androidnotificationsalarmmanagerandroid-pendingintent

Android: How to get pending intent remaining time


I have app that gives user notifications every day in week. No I want to get remaining time for the pending intent. I have store pending ID to database but I don't know how to get the pending intent time.

I set the repeating like this:

Intent notificationIntent = NotificationReciever.newIntent(this, plant.getPendingIntentID(day),
                            plant.getName() + " Čas: " + mHours + ":" + mMinutes);

     PendingIntent pendingIntent =
                            PendingIntent.getBroadcast(getApplicationContext(), plant.getPendingIntentID(day), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

     AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
                    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, date.getTimeInMillis(), 24 * 60 * 60 * 1000, pendingIntent);

Solution

  • I figured out that if I store exact Day and Time when the notification gets fired I can always calculate the remaining time.