2012-07-29 46 views
0

我不知道爲什麼當我顯示通知時,在右上角顯示一些1/4/70日期?那是什麼?我如何擺脫它?Android通知在角落顯示一些奇怪的日期

代碼:

public static void showNotification(int id, String message, String title, String body) 
    { 
     int drawable = 0; 
     switch (id) 
     { 
      case NOTIFICATION_NEW_MAIL: 
       drawable = R.drawable.ic_notify_mail; 
       break; 

      case NOTIFICATION_AVAILABLE_TRIPS: 
       drawable = R.drawable.ic_notify_trip; 
       break; 
     } 

     NotificationManager notifyManager = (NotificationManager)MyApplication.Me.getSystemService(Context.NOTIFICATION_SERVICE); 
     Notification notification = new Notification(drawable, message, SystemClock.elapsedRealtime() + 1000); 
     notification.defaults |= Notification.DEFAULT_SOUND; 

     Intent notificationIntent= new Intent(MyApplication.Me, MailListActivity.class); 
     switch (id) 
     { 
      case NOTIFICATION_NEW_MAIL: 
       notificationIntent = new Intent(MyApplication.Me, MailListActivity.class); 
       break; 

      case NOTIFICATION_AVAILABLE_TRIPS: 
       notificationIntent = new Intent(MyApplication.Me, TripListActivity.class); 
       break; 
     } 

     PendingIntent contentIntent = PendingIntent.getActivity(MyApplication.Me, 0, notificationIntent, 0); 
     notification.setLatestEventInfo(MyApplication.Me, title, body, contentIntent); 

     notifyManager.notify(id, notification); 
    } 

截圖:

enter image description here

回答

0

該通知構造函數顯然已被棄用,但無論如何,該構造函數中的最後一個參數應該在unix時間引用創建通知的時間。 SystemClock.getEllapsed time返回自系統啓動以來的時間量http://developer.android.com/reference/android/os/SystemClock.html。例如。在你的情況中,你說的是最近創建的通知,但是在unix時間,你說你真的接近1970年代。使用System.getCurrentTimeMillis()來代替。

編輯:接近1970我的意思是Unix時間是從1970年開始測量的毫秒數。所以如果你說0ms你說的是1月1日。如果你通過86,400,000ms(一天中的ms)再稱1月2日,1970年通過在經過時間的推移,因爲開機時,它可能會報告你的一兩天,從1月1日,1970年見http://en.wikipedia.org/wiki/Unix_time

+0

構造函數已棄用,但我正在開發API7,因此它只是我擁有的東西 – katit 2012-07-29 16:24:46

+0

儘管如此,仍然使用System.getCurrentTimeMillis() - 它可以爲您提供正確的時間。正如我寫的,SystemClock.getEllapsedTime返回自系統啓動以來的時間量。 getCurrentTimeMillis()從1970年1月1日起返回ms,並將正確的時間放在通知框中。另外,如果這項工作可以接受這個答案? – aamit915 2012-07-29 19:35:21

+0

答案已被接受,但它是'System.currentTimeMillis();',而不是'getCurrentTimeMillis()' – katit 2012-07-29 21:14:34

0

請告訴我該SystemClock的事情嗎?使用System.currentTimeMillis()或System.nanoTime()有什麼問題?

另外,嘗試寫一個toClock()函數,它會將其轉換爲12hr/24hr格式的時間字符串。再次,當我回到辦公室時,更多的是週一(示例代碼可用)。

0

我覺得你的意思是說:

Calendar canlender = Calendar.getInstance(); 
    canlender.setTimeInMillis(System.currentTimeMillis()); 
    canlender.add(Calendar.MILLISECOND, 1000); 
    long TimeInMillised = canlender.getTimeInMillis(); 
    Notification notification = new Notification(drawable, message, TimeInMillised); 

試試吧!