如何阅读通知Firebase oncreate Action

时间:2017-04-27 16:08:07

标签: java android firebase firebase-cloud-messaging

我正在使用fireBase重新通知并在backgroud中处理它,我需要获取onCreate()上的数据方法:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
   @Override
    public void onCreate() {
        super.onCreate();
//how to get notification body here not in onMessageReceived(RemoteMessage remoteMessage) 
    }
}

1 个答案:

答案 0 :(得分:0)

消息在onMessageReceived()中处理,请参见底部的示例。

Firebase有多种邮件类型 - 通知邮件和数据邮件:https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    //notification message
    RemoteMessage.Notification notification = remoteMessage.getNotification();
    String body = notification.getBody();

    //data message
    Map<String, String> data = remoteMessage.getData();
}