0

when I try to send the notification with custom data in Firebase I did not get the notification in the background

My Firebase service Code is:

In On message Receive method

    @Override 
public void onMessageReceived(RemoteMessage remoteMessage) {

        Log.e("fcm", "received notification");

        if (remoteMessage == null)
            return;

        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {

            Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());

            try {
                int badge = Integer.parseInt(remoteMessage.getData().get("badge"));
                String message = remoteMessage.getData().get("message");
                String timestamp = remoteMessage.getData().get("timestamp");
                handleDataMessage(badge,message,timestamp);

                badgeStore = Integer.parseInt(remoteMessage.getData().get("badge"));

            } catch (Exception e) {
                Log.e(TAG, "Exception: " + e.getMessage());
            }
        }

    }
Ronak Thakkar
  • 2,515
  • 6
  • 31
  • 45

1 Answers1

0

please register your firebase service in menifest file

<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>

Add these lines inside the application tag to set the custom default icon and custom color:

<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_stat_ic_notification" />

<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/colorAccent" />
Mukesh Y.
  • 869
  • 1
  • 16
  • 36