[英]Android notification showing some weird date in a corner
我不確定為什么當我顯示通知時,右上角會顯示一些1/4/70日期嗎? 那是什么? 我如何擺脫它?
碼:
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);
}
屏幕截圖:
那是什么SystemClock的東西? 使用System.currentTimeMillis()或System.nanoTime()有什么問題?
另外,嘗試編寫toClock()函數,將其轉換為12hr / 24hr格式的時間字符串。 再次,星期一回到辦公室時,星期一有更多(可用示例代碼)。
該通知構造函數顯然已被棄用,但是無論如何,該構造函數中的最后一個參數何時應該在UNIX時間中引用創建通知的時間。 SystemClock.getEllapsed time返回自系統啟動以來的時間http://developer.android.com/reference/android/os/SystemClock.html 。 例如,您是說該通知是最近才創建的,但是在UNIX時間中,您是說您確實接近1970年。請改用System.getCurrentTimeMillis()。
編輯:接近1970,我的意思是Unix時間是從1970年初開始的毫秒數。因此,如果您說0ms就是說Jan1。如果您傳入86,400,000ms(一天中的ms),您是說Jan 2 ,1970年。通過傳入自啟動以來所經過的時間,它很可能會將您報告為從1970年1月1日開始的一兩天。請參閱http://en.wikipedia.org/wiki/Unix_time
我認為您的意思是:
Calendar canlender = Calendar.getInstance();
canlender.setTimeInMillis(System.currentTimeMillis());
canlender.add(Calendar.MILLISECOND, 1000);
long TimeInMillised = canlender.getTimeInMillis();
Notification notification = new Notification(drawable, message, TimeInMillised);
試試吧!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.