简体   繁体   English

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

[英]Click on status bar notification and show details?

I wrote an app that saves local notification at specific time in future and when that time is reached it shows notification in status bar even if the app is not running. 我编写了一个应用程序,该应用程序会在以后的特定时间保存本地通知,并且当到达该时间时,即使该应用程序未运行,它也会在状态栏中显示通知。 My question is: it is possible to show some additional information to user when he clicks on notification in status bar? 我的问题是:当用户单击状态栏中的通知时,是否可以向用户显示一些其他信息?

Yes it is possible to display additional information when user taps on that particular notification. 是的,当用户点击该特定通知时,可能会显示其他信息。 While writing code to display notification, you will find one setLatestEventInfo method. 在编写代码以显示通知时,您将找到一个setLatestEventInfo方法。 Use it. 用它。 Its exactly what you need. 它正是您所需要的。

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);

  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM