4

I am using FirebaseInAppMessaging and it's works. Then i register action call back using FirebaseInAppMessagingClickListener, it's not calling.

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());

}

}

And i register this click listener in MainActivity's onCreate

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

i tried to register listener for two ways.

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

Or

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

`

And using gradle

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

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

4 Answers4

0

Could it be related to this issue opened 7 days ago? https://github.com/firebase/firebase-android-sdk/issues/681

0

For some reason, FirebaseInAppMessaging remove all listeners every time an activity goes to background. You can see this by putting a break point on removeAllListeners method of DeveloperListenerManager class. Registering your listener in the onResume method of your main activity is a way to deal with this problem.

0

Here is something you might want to try.

  1. Create a new campaign in Firebase Console (refer to https://firebase.google.com/docs/in-app-messaging/compose-campaign). Don't publish it yet, because you can't test a published campaign.

  2. In "Scheduling" step, select on_foreground as the trigger event.

  3. In your app's onResume(), add listeners.

Firebase.inAppMessaging.addClickListener { inAppMessage, action ->
    // ...
}

Firebase.inAppMessaging.addImpressionListener { inAppMessage ->
    // ...
}
  1. Run your app and put it in the background by pressing HOME button.

  2. Send the test message from Firebase Console's Test on device, which is in "Style and content" step.

  3. Bring your app to foreground and tap on your campaign's button that is not marked as "Use dismiss as the action".

At this point, both ClickListener and ImpressionListener should be called.

In-App Messaging removes all listeners except DismissListener when the app goes to the background, so you'd need to add listeners in onResume() if you want to use on_foreground as the trigger event.

solamour
  • 2,764
  • 22
  • 22
-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)

        }