显示消息回调不调用 - firebase应用程序内消息传递



我正在尝试自定义firebase In-App消息。

我正在关注本文:https://firebase.google.com/docs/in-app-messaging/customize-messages

根据文章,我创建了自己的 firebaseinappMessaggingDisplay 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");
    }
}

然后用无头的firebase In-App Messaging SDK

注册了此实现
public class MyApplication extends Application{
@Override
public void onCreate() {
    super.onCreate();
    FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(new MyMessageDisplayImplementation());
}

}

我的问题是,我没有得到displyamessage()回调。

当我从应用程序类中评论代码线," FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(new MyMessageDisplayImplementation());"时,它将显示默认消息。但是,当我将此代码放回时,什么都没有发生。

如果有人了解此应用程序内消息自定义,请提供帮助。

此github问题评论解决了我的问题。

简而言之,问题是由Firebase SDK恢复时设置自己的侦听器引起的,用setMessageDisplayComponent覆盖您设置的侦听器。

为了解决问题,我将自己的侦听器代码从onStart移至onResume,确保我的侦听器将是最后一个添加的侦听器,并成为接收消息的一个。

firebase doc上的信息有点令人困惑。实际上非常简单。

在应用程序级别gradle文件中添加了这些依赖项。

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

注意:我们不需要添加" 实现'com.google.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)
}

最新更新