0

我正在處理一個項目,需要向安裝了我的應用程序的Android設備發送推送通知。我已經按照Firebase的快速入門教程完成了該操作,併成功地在我的Android設備上收到了通知。推送通知數據

問題:如果您點擊應用程序圖標而不是推送通知,如何訪問通知數據?

回答

1

,當你收到你把你的應用程序內部的消息存儲在共享的偏好與正確的密鑰是這樣的:

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); 
SharedPreferences.Editor editor = sharedPref.edit(); 
editor.putString("recent_notification_key", "your_notification_data"); 
editor.commit(); 

現在,當你點擊你的應用程序,裏面的第一個活動寫的onCreate下面的代碼:

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); 
String notificationString = sharedPref.getString("recent_notification_key", defaultValue); 

if (notificationString !=null && !notificationString.equals("")){ 
\\ you received new notification 
}