Firebase 消息推送遇到的坑

Firebase消息推送分为前台和后台:

1,当应用处于前台的时候,推送的消息会走onMessageReceived方法,我们可以根据参数RemoteMessage获取需要的参数,流程是没问题的;

2,当应用处于后台的时候,发现推送消息的时候不会走onMessageReceived方法,点击推送通知会走默认进入应用,获取不了我们需要的数据,无法特定跳转,后来发下官方文档说明;

Handle messages in a backgrounded app
When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.

This includes messages that contain both notification and data payload. In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

翻译之后为:处理后台应用程序中的消息当应用程序位于后台时,Android会将通知消息定向到系统托盘。默认情况下,用户点击通知将打开应用程序启动程序。这包括包含通知和数据负载的消息。在这些情况下,通知将传递到设备的系统托盘,数据有效负载将在启动程序活动意图的附加部分中传递。

通俗点就是,当应用处于后台,推送消息的数据会走启动页,通过getIntent().getExtra()获取所有需要的参数数据;

 

 

你可能感兴趣的:(Firebase 消息推送遇到的坑)