Android的提醒! [英] Android reminder!

查看:142
本文介绍了Android的提醒!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下用做提醒的安卓哪些服务以及如何......比方说:从现在开始10分钟后给我通知在通知栏...

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...

谢谢您的回答

推荐答案

显然,你应该使用AlarmManager,以建立东西,在特定时期内执行。

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);

在这里的时间为你的时间,应在OnAlarmReceiver执行的东西。 然后,就在实现方法

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);
}

享受。

这篇关于Android的提醒!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆