简体   繁体   中英

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

  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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