0

I have an android app where a user can add projects etc, I'd like to implement a feature where a user can select at which intervals they want to be reminded (would like to have a push notification to be sent when the time is reached).

I am not using Firebase in my project just to make it clear.

For example when a user creates a project they can choose to be reminded 1 week,1 day, 1 hours etc before the projects due date and the app would constantly check for this condition despite the app being open or closed.

At the moment I have set up the difference between the due date and the current date using LocalDateTime to check the difference in minutes.

Here is the method I'm using to get this, but now I'd like to automatically notify the user when a project reaches this specific time. I'm unsure on what to use to check for this, any suggestions would be appreciated

    @RequiresApi(api = Build.VERSION_CODES.O)
    public boolean isProjectExpired(LocalDateTime dateDue) {
        LocalDateTime current = LocalDateTime.now();
        long minutes = ChronoUnit.MINUTES.between(current, dateDue);

        // Here, notify the user when 1 hour is left till the project due date
        if(minutes == 60) {
            System.out.println("PROJECT EXPIRES IN 1 HOUR: " + getTitle());
        }

        // send push notification based on time remaining
        // Remind 2 weeks (336 hours) (20160 minutes) before due date
        // Remind 1 week (168 hours) (10080 minutes) before due date
        // Remind 1 day (24 hours) (1440 minutes) before due date
        // Remind 1 hour (60 minutes) before due date
        // Remind 30 minutes before due date
        return current.isAfter(getDateDue());
    }

ServletException
  • 171
  • 1
  • 15
  • Always compare server time and you need a service getting remaining time... Somewhere call like main or splash if it's expired or what you want compare then show alert or notification – Gobu CSG Jul 07 '22 at 19:29
  • 1
    There are many ways to achieve this try this answer https://stackoverflow.com/a/32275911/14017100 – ARCHER Jul 07 '22 at 19:31

0 Answers0