![](/img/trans.png)
[英]What is the difference between In-App Messaging and In-App Messaging Display in Firebase
[英]Display Message callback not invoking - Firebase in-app messaging
我正在尝试自定义 Firebase 应用内消息。
我正在关注这篇文章: https : //firebase.google.com/docs/in-app-messaging/customize-messages
根据文章,我创建了自己的FirebaseInAppMessagingDisplay类实现。
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");
}
}
然后使用无头 Firebase 应用内消息 SDK 注册此实现
public class MyApplication extends Application{
@Override
public void onCreate() {
super.onCreate();
FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(new MyMessageDisplayImplementation());
}
}
我的问题是,我没有收到 displyaMessage() 回调。
当我注释掉这行代码时, " FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(new MyMessageDisplayImplementation());"
从 Application 类,它显示默认消息。 但是,当我放回这段代码时,什么也没有发生。
如果有人对此应用内消息定制有更好的了解,请提供帮助。
Firebase文档上的信息有点混乱。 其实它很简单。
在应用程序级别gradle文件中添加了这些依赖项。
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation ("com.google.firebase:firebase-inappmessaging:17.0.3")
注意:我们不需要添加“ 实现'com.google.firebase:firebase-inappmessaging-display:17.1.1 '”依赖项
在开始活动时注册DisplayMessage组件。
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)
}
这个 GitHub 问题评论为我解决了这个问题。
简而言之,问题是由于 Firebase SDK 在您的活动恢复时设置了自己的侦听器,覆盖了您使用setMessageDisplayComponent
设置的侦听器。
为了解决这个问题,我将自己的侦听器代码从onStart
移到了onResume
,确保我的侦听器是最后添加的侦听器并成为接收消息的侦听器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.