繁体   English   中英

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

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

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

是的,当用户点击该特定通知时,可能会显示其他信息。 在编写代码以显示通知时,您将找到一个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);

  }

暂无
暂无

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

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