简体   繁体   中英

How can I import firebase in-app-messaging-display api's source code into my android project?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM