点击状态栏通知并显示详细信息?

时间:2012-09-25 10:35:31

标签: android

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

1 个答案:

答案 0 :(得分: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);

  }
相关问题