【问题标题】:Push Notification data推送通知数据
【发布时间】:2017-01-04 07:06:37
【问题描述】:

我正在处理一个需要向安装了我的应用程序的 android 设备发送推送通知的项目。我已经按照 Firebase 的快速入门教程完成了这项工作,并在我的 Android 设备上成功收到了通知。

问题:如果您点击的是应用程序图标而不是推送通知,您如何访问通知数据?

【问题讨论】:

    标签: android firebase push-notification firebase-cloud-messaging


    【解决方案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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 2017-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多