everybody, I m using firebase to receive a push notification from the server. Everything working fine when the application is running. I got the notification, I handle it and show it over notification tray. Seems perfect. Here is my code.
public class FirebasePushService extends FirebaseMessagingService {
private static final String TAG = "FireBase main service ";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "Got Message: " + remoteMessage.getFrom());
try {
if (remoteMessage != null && remoteMessage.getNotification() != null
&& remoteMessage.getNotification().getBody() != null) {
String body = remoteMessage.getNotification().getBody();
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + body );
}
} catch (JSONException e) {
e.printStackTrace();
}
}}
Manifest code.
<service android:name="app.asparagus.com.asparagus.firebase.FirebasePushService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
. The issue is when the application is closed. No log works of this class, nothing. But here is the interesting part. I can see the whole JSON from the server, and it is shown on notification tray ( whole JSON object is displayed). Really not getting what's wrong in my code. Check the image. 1- The success case.
Sorry for late reply I have found the solution and In case anyone else have issue with it.Here is from firebase documentation. Message types
With FCM, you can send two types of messages to clients:
Notification messages, sometimes thought of as "display messages."
Data messages
, which are handled by the client app.
Notification messages contain a predefined set of user-visible keys. Data messages, by contrast, contain only custom key-value pairs. Notification messages can contain an optional data payload that is delivered when users tap on the notification.
Use scenario
Notification message FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys and an optional data payload of custom key-value pairs.
How to Send In a trusted environment such as Cloud Functions or your app server, use the Admin SDK or the HTTP and XMPP APIs: Set the notification key. May have optional data payload. Always collapsible. Use the Notifications composer: Enter the Message Text, Title, etc., and send. Add optional data payload by providing Custom data. Always collapsible.
Use scenario
Data message Client app is responsible for processing data messages. Data messages have only custom key-value pairs. In a trusted environment such as Cloud Functions or your app server, use the Admin SDK or the HTTP and XMPP APIs: Set the data key only. Can be either collapsible or non-collapsible.