2012-09-25 40 views
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); 

    } 
+0

是的,但這只是狀態欄中的信息,如果您在狀態欄中單擊此通知,該怎麼辦?是否有可能讓信息烤麪包? – gorgi93

+1

請參閱setLatestEventInfo有一個名爲activity的參數,它將在用戶點擊該通知時啓動該活動。如果你只想要烤麪包,然後使用服務。編寫代碼以在Service類的onStart中顯示Toast。 –