2012-04-21 54 views
0

我在我的應用程序中使用狀態欄通知,並通過單擊按鈕發送它。但是當通知到達時,打開時顯示錯誤的日期(在我的情況下顯示爲1/1/1970)。如何在Android狀態欄通知中顯示正確的當前時間?

Notification

我使用下面的代碼顯示狀態欄通知。

@Override 
    public void onClick(View v) 
    { 
     // TODO Auto-generated method stub 
     NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     Notification notification = new Notification(R.drawable.ic_launcher, "Notify", 1000); 

     Context context = getApplicationContext(); 
     Intent intent = new Intent(this, NotificationActivity.class); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); 
     notification.setLatestEventInfo(context, "TITLE", "MESSAGE", pendingIntent); 

     notificationManager.notify(R.id.button1, notification); 

    } 

回答

3

從我的博客文章在這裏拍攝:
http://blog.blundellapps.com/notification-for-a-user-chosen-time/

您應該創建您的通知是這樣的:

// 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); 
+0

謝謝Blundell.It工作。 – AB1209 2012-04-23 14:26:53

相關問題