.setWhen(System.currentTimeMillis())
是在推送通知android中設置時間的代碼,結果就像15.54
。但是如果我想在幾秒鐘的時間內像這樣設置時間15:54:02
我應該怎麼做?你能幫我或提供示例源代碼嗎?如何在第二次設置通知的時間和日期?
這是我的通知管理器源代碼。
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
Notification notification;
notification = mBuilder.setSmallIcon(R.drawable.logo).setTicker(title).setWhen(0)
.setAutoCancel(true)
.setContentIntent(resultPendingIntent)
.setContentTitle(title)
.setSmallIcon(R.drawable.logo)
.setWhen(System.currentTimeMillis())
.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher))
.setContentText(message)
.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults = Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults = Notification.DEFAULT_ALL;
int id = (int) System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(ID_SMALL_NOTIFICATION, notification);
notificationManager.notify(id, notification);
}
以'notification.defaults'擺弄看起來無意義的給我。我會投票刪除這個,不要混淆讀者,無論是在這裏還是在實際的代碼庫中。 –