Reputation: 11
I have created android app. Inside app, user can set time for notification so that at that time if user will not performed particular action then application should send notification to him automatically. I am new in android Please suggest me what i have to do (either create a backend services which will check either user set time reached then send notification to him or somelese solution). Please help
Upvotes: 0
Views: 527
Reputation: 1023
You can use an AlarmManager, with that you can set the time of the notification.
This AlarmManager is received by a class that extends BroadCastReceiver and that launchs what to be done, from that launched class you can define a service that can send the notification.
The way to set an alarmmanager that fires that class that extends BroadCastReceiver is:
Intent intent = new Intent(this, classExtendingBroadCastReceiver);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(
ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,//System.currentTimeMillis()+20*1000
time
, pendingIntent);
Where time is the time when you want the alarm to fire.
Hope it helps.
Upvotes: 1