我使用以下代码来显示通知
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("My notification")
.setContentText("Hello World!");
Intent resultIntent = new Intent(this, MainActivity.class);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
You can set an explicit value with setWhen();
if you don't it defaults to the time that the system received the notification.
问题是我没有收到通知中的defalut time
。
-------------------- WORK AROUND --------------------- < /强>
使用System.currentTimeMillis()
获取当前时间,然后将其传递给when()
long curr_time = System.currentTimeMillis();
mBuilder.setWhen(curr_time);
如果没有解决方法可以解决这个问题,请告诉我。 :)