1

I am trying to customise the firebase in-app messages.

I am following this article :https://firebase.google.com/docs/in-app-messaging/customize-messages

As per the article I have created my own implementation of FirebaseInAppMessagingDisplay class.

import com.google.firebase.inappmessaging.FirebaseInAppMessagingDisplay;
import com.google.firebase.inappmessaging.FirebaseInAppMessagingDisplayCallbacks;
import com.google.firebase.inappmessaging.model.InAppMessage;

public class MyMessageDisplayImplementation implements 
FirebaseInAppMessagingDisplay {
    @Override
    public void displayMessage(InAppMessage inAppMessage
        , FirebaseInAppMessagingDisplayCallbacks 
    firebaseInAppMessagingDisplayCallbacks) {
         Log.e("INAPP_MESSAGE","received an inapp message");
    }
}

Then registered this implementation with the headless Firebase In-App Messaging SDK

public class MyApplication extends Application{

@Override
public void onCreate() {
    super.onCreate();
    FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(new MyMessageDisplayImplementation());
}

}

My problem is that, I am not getting the displyaMessage() callback.

When I commented out the line of code, " FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(new MyMessageDisplayImplementation());" from Application class, it is showing the default message. But, nothing is happening when I put this code back.

Please help if anyone knows better idea about this in-app message customisation.

Suneesh Ambatt
  • 1,347
  • 1
  • 11
  • 41

2 Answers2

2

This GitHub issue comment fixed the problem for me.

In short, the problem is caused by the Firebase SDK setting its own listener when your activity resumes, overwriting the listener you set with setMessageDisplayComponent.

To fix the issue I moved my own listener code from onStart to onResume, ensuring my listener would be the last one added and become the one that receives the messages.

Simon Raes
  • 442
  • 4
  • 15
1

The information on the firebase doc is little bit confusing. Actually its very simple.

Added these dependencies in app level gradle file.

implementation 'com.google.firebase:firebase-core:16.0.8'
implementation ("com.google.firebase:firebase-inappmessaging:17.0.3")

Note: We don't need to add "implementation 'com.google.firebase:firebase-inappmessaging-display:17.1.1'" dependency

Register the DisplayMessage component on starting activity.

import com.google.firebase.inappmessaging.FirebaseInAppMessaging
import com.google.firebase.inappmessaging.FirebaseInAppMessagingDisplay

///////

override fun onStart() {
    super.onStart()
    Log.e("MESSAGE", "activity started")
    var firebaseInAppMessagingDisplay = FirebaseInAppMessagingDisplay { inAppMessage, cb ->
        // You can show the message here.
        // The variable inAppMessage has all information about the campaign that we putting in console (title, content, image url.. etc)
        Log.e("MESSAGE", "Display Message callback invoked")
    }
    FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(firebaseInAppMessagingDisplay)
}
Suneesh Ambatt
  • 1,347
  • 1
  • 11
  • 41