Android 如何设置在某个事件临近时显示的通知。
我正在制作一个类似于待办事项列表的应用程序。现在,我希望我的应用程序在离某个“待办事项”活动还有一天的时候显示通知。我想弹出的通知,即使应用程序没有运行。我怎样才能做到这一点?Android 如何设置在某个事件临近时显示的通知。,android,android-notifications,Android,Android Notifications,我正在制作一个类似于待办事项列表的应用程序。现在,我希望我的应用程序在离某个“待办事项”活动还有一天的时候显示通知。我想弹出的通知,即使应用程序没有运行。我怎样才能做到这一点? 读这本书对我来说并不是很清楚 也许这可以澄清一点: 如果您希望在todo数据的前一天收到通知,则只需从该日期减去1天即可 1) 报警 getSystemService(Context.ALARM_SERVICE).set(AlarmManager.RTC, date.getTimeInMillis(), pending
读这本书对我来说并不是很清楚 也许这可以澄清一点: 如果您希望在todo数据的前一天收到通知,则只需从该日期减去1天即可 1) 报警
getSystemService(Context.ALARM_SERVICE).set(AlarmManager.RTC, date.getTimeInMillis(), pendingIntent);
2) 警觉
3) 显示通知
// This is the 'title' of the notification
CharSequence title = "Alarm!!";
// This is the icon to use on the notification
int icon = R.drawable.ic_dialog_alert;
// This is the scrolling text of the notification
CharSequence text = "Your notification time is upon us.";
// What time to show on the notification
long time = System.currentTimeMillis();
Notification notification = new Notification(icon, text, time);
// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, SecondActivity.class), 0);
// Set the info for the views that show in the notification panel.
notification.setLatestEventInfo(this, title, text, contentIntent);
// Clear the notification when it is pressed
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Send the notification to the system.
mNM.notify(NOTIFICATION, notification);
您可以创建一个
Android服务
并使用唤醒意图服务
来安排警报,当您捕捉到警报时,您可以显示一个警报框
您可以在下面的代码链接中找到: