4

I am trying to customize the firebase in-app-messaging-display's UI of "Image Only" and "Modal" mode. So I turned to the official documentation, but it is quite simple, by saying: Creating your own display is a two step process: 1.Write your own implementation of the FirebaseInAppMessagingDisplay class. 2.Register that implemenation with the headless Firebase In-App Messaging SDK.

I wonder how can I import in-app-messaging-display's source code into my project and make it work as a library.

I have downloaded its source code from github:https://github.com/firebase/firebase-android-sdk/tree/master/firebase-inappmessaging-display, tried to import it as a module, but after I selected the Source directory, Android Studio hints that: Specify location of the Gradle or Android Eclipse project. I also have tried to copy the source code into my project's libs directory and added this: include ':libs:firebase-inappmessaging-display' into my settings.gradle file and this: implementation project(':libs:firebase-inappmessaging-display') into my app's gradle dependency. When sync building Android Studio reports errors like this: ERROR: Unable to resolve dependency for ':XXXXXXXX': Could not resolve project :libs:firebase-inappmessaging-display.

Any suggestion will be highly appreciated.

geekShaw
  • 161
  • 1
  • 9
  • Did you got any solution? I am also in the same situation. – Suneesh Ambatt Apr 10 '19 at 13:12
  • Hi @geekShaw, could you provide more information about how do you solve it? I trying to import the firebase sdk as you suggest but I cannot add it to my project. Thank you so much. – Jon Jun 08 '20 at 18:20

1 Answers1

2

The information on the doc is little bit confusing. I am also stuck with the same problem for long time. Actually its very simple.

Add these dependencies in your app level gradle file.

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

Register Your 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
  • 1
    Thank you for your answer. I have solved this problem by importing the firebase sdk's source code as subproject instead of library and modifying their code. – geekShaw Apr 11 '19 at 23:00
  • @SunSun I'm trying to implement your code. I create a campaign in the console that show it on launch, but the callback is never invoked. How do you connect this code with an specific campaign?. Tank you so much – Jon Jun 08 '20 at 18:17