我知道如何在某个点击事件后X毫秒启动通知。代码如下:
通知代码如下:
我该如何设置通知在特定的日期和时间出现,比如说10月1日晚上7点?
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
triggerNotification();
}
};
timer.schedule(timerTask, 3000);
通知代码如下:
CharSequence title = "Hello";
CharSequence message = "Hello, Android!";
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, "A New Message!", System.currentTimeMillis());
Intent notificationIntent = new Intent(this, AndroidAlarmService.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(AndroidAlarmService.this, title, message, pendingIntent);
notification.defaults = Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(NOTIFICATION_ID, notification);
我该如何设置通知在特定的日期和时间出现,比如说10月1日晚上7点?
Calendar calendar = Calendar.getInstance(); calendar.set(int year, int month, int date, int hour, int minute, int second); long when = calendar.getTimeInMillis();
- eladrich