So I want my app to send a notification at 8:00 a.m. everyday subjected to whether there is an event on that day or not.
I have a SQLlite DB which stores the dates on which notification is to be sent. What I want from my app, is this- Everyday at 8 in the morning, it should check if there is an event for today. And if there is an event for that day, then send a notification.
I have already implemented the part with the DB and the notification. I just need to implement the part where the app checks the DB at 8 a.m. everyday.
**Update: ** I made a service which checks if the current time is 8:00 or not. Following is the code for that service.
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
System.out.println("inside on start command for service");
myPrefs = this.getSharedPreferences("settings", this.MODE_PRIVATE);
checkTime();
return START_STICKY;
}
// to check if the time for alarm is here
private void checkTime() {
// TODO Auto-generated method stub
try{
System.out.println("inside check time");
Calendar cal;
cal = Calendar.getInstance();
if (08 == cal.get(cal.HOUR_OF_DAY) && 00 == cal.get(cal.MINUTE)) {
// to call db and check for events
nm = new MyNotificationManager(this);
if (nm.checkEvent()) {
nm.setNotifications();
}
}
}catch(Exception e){
System.out.println("inside exception for check time "+e.toString());
}
}
The problem is that the service is only checking the time once. How to make it check the time every minute? Can anyone please help me?