2012-04-21 56 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

相关问题