android中的本地通知立即开始,而不是在给定的时间

ton*_*099 2 time notifications android

    long when = Calendar.getInstance().getTimeInMillis();
    when += 10000;

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
            getApplicationContext())
            .setWhen(when)
            .setContentText(notificationContent)
            .setContentTitle(notificationTitle)
            .setSmallIcon(smalIcon)
            .setAutoCancel(true)
            .setTicker(notificationTitle) 
            .setLargeIcon(largeIcon)
            .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_VIBRATE| Notification.DEFAULT_SOUND)
            .setContentIntent(pendingIntent);
Run Code Online (Sandbox Code Playgroud)

这在onCreate中运行,但是,我的通知会在应用程序启动时立即创建,而不是在10秒后创建.怎么了 ?

甚至

.setWhen(System.currentTimeMillis()+10000)
Run Code Online (Sandbox Code Playgroud)

不会在10秒后显示.它直接显示.

Squ*_*onk 6

setWhen(...)... 的文档

添加与通知相关的时间戳(通常是事件发生的时间).它默认显示在通知内容视图中; 使用setShowWhen来控制它.

setWhen(...)方法没有设置Notification应该显示何时的时间(延迟).它用于显示某个事件发生的时间.

例如,假设您的应用程序监视器接收SMS消息 - 当消息到达时,您将创建一个Notification说"您有新的SMS消息",并且您将用于setWhen(...)显示收到消息的时间.

如果要为事件设置特定延迟或固定时间以及Notification要显示的关联 ,请使用AlarmManager.