androidfirebaseandroid-custom-viewfirebase-in-app-messaging

Display Message callback not invoking - Firebase in-app messaging


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.


Solution

  • 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)
    }