2

我正在使用以下代码显示通知

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通知。

在此处输入图像描述

-------------------- 解决方法------------

使用获取当前时间System.currentTimeMillis(),然后将其传递给when()

long curr_time = System.currentTimeMillis();

mBuilder.setWhen(curr_time);

让我知道这是否可以在没有解决的情况下解决。:)

4

1 回答 1

2

这是 ICS 早期版本中的错误;从 4.0.3 版开始,时间戳应该会再次出现(在此处修复)。

于 2013-08-14T16:46:31.697 回答