5
我知道如何在點擊事件後X毫秒開始通知。這樣如何開始自定義日期和時間的通知?
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
triggerNotification();
}
};
timer.schedule(timerTask, 3000);
A碼凡通知代碼看起來像這樣
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點?
什麼可以作爲是否'bergnam'在10月1日下午7點說,'when'變量的結構? 'long when = 01/10/2011 7 PM;'? – androniennn
@bergnam只需簡單地使用Date對象設置日期,然後調用.getTime() – eladrich
'SimpleDateFormat dateLongue = new SimpleDateFormat(「DD MM yyyy HH:mm:ss」);'以及如何以及爲什麼調用.getTime? – androniennn