簡體   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