3

我正在使用FirebaseInAppMessaging并且它有效。然后我使用 注册动作回调FirebaseInAppMessagingClickListener,它没有调用。

public class InAppMessageClick implements FirebaseInAppMessagingClickListener, FirebaseInAppMessagingImpressionListener, FirebaseInAppMessagingDisplay {

String TAG = "InAppMessageClick";
@Override
public void messageClicked(InAppMessage inAppMessage, Action action) {
    // Determine which URL the user clicked
    String url = action.getActionUrl();
    LogUtils.i(TAG, "Action URL : "+url);
    // Get general information about the campaign
    CampaignMetadata metadata = inAppMessage.getCampaignMetadata();
   Log.i(TAG," Metadata : "+metadata);
}


@Override
public void impressionDetected(InAppMessage inAppMessage) {
    LogUtils.i(TAG, "impressionDetected Action URL : "+inAppMessage.getCampaignMetadata().getCampaignName());
}

@Override
public void displayMessage(InAppMessage inAppMessage, FirebaseInAppMessagingDisplayCallbacks firebaseInAppMessagingDisplayCallbacks) {
    LogUtils.i(TAG, "displayMessage Action URL : "+inAppMessage.getCampaignMetadata().getCampaignName());

}

}

我在 MainActivity 的 onCreate 中注册了这个点击监听器

InAppMessageClick inAppMessageClick = new InAppMessageClick();
    FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(inAppMessageClick);
    FirebaseInAppMessaging.getInstance().addClickListener(inAppMessageClick); 

我试图通过两种方式注册监听器。

InAppMessageClick inAppMessageClick = new InAppMessageClick();
FirebaseInAppMessaging.getInstance().addClickListener(inAppMessageClick);`

或者

FirebaseInAppMessaging.getInstance().addClickListener(inAppMessageClick, new Executor() {
            @Override
            public void execute(Runnable command) {
                LogUtils.i("MainActivity", "FIAM CLICKED EXECUTOR");
            }
       });

`

并使用 gradle

    implementation 'com.google.firebase:firebase-inappmessaging-display:18.0.2'

    implementation 'com.google.firebase:firebase-core:17.0.1' 
4

3 回答 3

0

可能与7天前打开的这个问题有关吗? https://github.com/firebase/firebase-android-sdk/issues/681

于 2019-08-09T10:50:23.510 回答
0

出于某种原因,每次活动进入后台时,FirebaseInAppMessaging 都会删除所有侦听器。removeAllListeners您可以通过在类的方法上放置一个断点来看到这一点DeveloperListenerManageronResume在您的主要活动的方法中注册您的侦听器是处理此问题的一种方法。

于 2021-11-18T22:11:33.217 回答
-1
Dependencies:
implementation platform('com.google.firebase:firebase-bom:26.6.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-inappmessaging-display-ktx'
implementation 'com.google.firebase:firebase-inappmessaging-ktx'

code on MainActivity onCreateMethod:
val firebaseIam = Firebase.inAppMessaging
firebaseIam.addClickListener { inAppMessage, action ->
            //write your functionality
            Log.d("here","successful)

        }
于 2021-03-03T10:49:04.630 回答