0

我编写了一个应用程序,可以在将来的特定时间保存本地通知,当到达那个时间时,即使应用程序没有运行,它也会在状态栏中显示通知。我的问题是:当用户点击状态栏中的通知时,是否可以向用户显示一些附加信息?

4

1 回答 1

1

是的,当用户点击该特定通知时,可以显示其他信息。在编写显示通知的代码时,您会发现一个 setLatestEventInfo 方法。用它。它正是您所需要的。

public void createNotification(View view) {
    NotificationManager notificationManager = (NotificationManager) 
          getSystemService(NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.icon,
        "A new notification", System.currentTimeMillis());
    // Hide the notification after its selected
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    Intent intent = new Intent(this, NotificationReceiver.class);
    PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
    notification.setLatestEventInfo(this, "This is the title",
        "This is the text", activity);
    notification.number += 1;
    notificationManager.notify(0, notification);

  }
于 2012-09-25T10:42:33.780 回答