Reputation: 924
I have a function called show_notification()
that I call when the user hits a button. The point is that instead of showing the notification once he clicks [as in the function below], I want to show this notification at a specific time= hours:mins
Where hours and minutes are two integers having the value of time I want [for example hour=22 and minutes=40..meaning fire this notification at 22:40 [10:40 pm] ]. By the way, this alarm should be repeated every day at same time.
public void show_notification() {
CharSequence notify_msg="Don't foget!";
CharSequence title= "you ve been notified by My app";
CharSequence details= "It works!";
NotificationManager nm= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify= new Notification(android.R.drawable.stat_notify_more,
notify_msg,
System.currentTimeMillis());
Context mycontext= ActA.this;
Intent myintent= new Intent (mycontext, ActA.class);
PendingIntent pending= PendingIntent.getActivity(mycontext, 0, myintent, 0); ///0's are not applicable here
notify.setLatestEventInfo(mycontext, title, details, pending);
nm.notify(0, notify);
}
I hope you can answer in details because I am a very new developer.
Upvotes: 3
Views: 7729
Reputation: 6514
It is quite simple. You can use alarm manager for it. You might need to modify the manifest file and register the application for getting notification from alarmmanager. now you can ask the alarm manager class to send a message on the desired time which your application will receive.
You will have to program your activity in a way that it responds to this message and displays a notification to the user.
Upvotes: 8