Android 安卓提醒!

Android 安卓提醒!,android,notifications,Android,Notifications,我想问一下在安卓系统中使用哪种服务以及如何进行提醒。。。假设:10分钟后,在通知栏中显示通知 感谢您的回答您应该使用。通过它,您可以计划要交付的意图。创建一个来获取它并显示通知。显然,您应该使用AlarmManager来设置要在给定时间段内执行的内容 AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, OnAlarmRec

我想问一下在安卓系统中使用哪种服务以及如何进行提醒。。。假设:10分钟后,在通知栏中显示通知


感谢您的回答

您应该使用。通过它,您可以计划要交付的意图。创建一个来获取它并显示通知。

显然,您应该使用AlarmManager来设置要在给定时间段内执行的内容

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);
这段时间是指你完成某件事情的时间,而这件事情应该在你的大脑中执行。 然后,只需在中实现方法

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

享受吧。

我猜像这样的人,你会在10分钟后启动runnable,然后在runnable的代码中打开一个通知

Runnable reminder = new Runnable()
{
    public void run()
    {
        int NOTIFICATION_ID = 1324;
        NotificationManager notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        Notification note = new Notification(R.drawable.icon, "message", System.currentTimeMillis());

        // Add and AUTO_CANCEL flag to the notification, 
        // this automatically removes the notification when the user presses it
        note.flags |= Notification.FLAG_AUTO_CANCEL;    

        PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this, ActivityToOpen.class), 0);

        note.setLatestEventInfo(this, "message", title, i);
        notifManager.notify(NOTIFICATION_ID, note);
    }
};

Handler handler = new Handler();
handler.postDelayed(reminder, 600000);

写了一篇教程。通知提醒: