Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android reminder!

I would like to ask which service and how to use to make reminder in android... Let's say: after 10 minutes from now show me notification in notification bar...

Thanks for your answer

like image 646
M.V. Avatar asked Mar 21 '26 16:03

M.V.


1 Answers

Obviously you should use AlarmManager in order to setup something to be executed in given PERIOD.

AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, OnAlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
SystemClock.elapsedRealtime(), PERIOD, pi);

where the PERIOD is your time to something that should be executed in OnAlarmReceiver. And then, just implement method in

@Override
public void onReceive(Context context, Intent intent) {
    NotificationManager nm = (NotificationManager);
    context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification();
    notification.tickerText = "10 Minutes past";
    nm.notify(0, notification);
}

Enjoy.

like image 64
ACM64 Avatar answered Mar 23 '26 05:03

ACM64



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!