4

I'm exploring Firebase In-App Messaging, wherein when I'm triggering an event,I'm able to view my banner/modal dialog which I have set in my Firebase console.

However I see an option to set custom data in the console under the following path:

In-App Messaging -> Compose Campaign -> Additional Options

So I have set the key-value pairs as shown below:

enter image description here

So, now I want to retrieve this data in my android app.How can I retrieve the data?

I have tried the following codes, but it didn't work:

1.

    FirebaseInAppMessaging.getInstance().triggerEvent("my_event");
    FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(new FirebaseInAppMessagingDisplay() {
        @Override
        public void displayMessage(@NonNull InAppMessage inAppMessage, @NonNull FirebaseInAppMessagingDisplayCallbacks firebaseInAppMessagingDisplayCallbacks) {
            CampaignMetadata campaignMetadata = inAppMessage.getCampaignMetadata();
            MessageType messageType = inAppMessage.getMessageType();
    //it doesn't give my key-value data
    //I can't see any methods like getData() which returns an object
        }
    });
    FirebaseInAppMessaging.getInstance().addClickListener(new FirebaseInAppMessagingClickListener() {
        @Override
        public void messageClicked(@NonNull InAppMessage inAppMessage, @NonNull Action action) {
            Button button = action.getButton();
        }
    });
    FirebaseInAppMessaging.getInstance().addImpressionListener(new FirebaseInAppMessagingImpressionListener() {
        @Override
        public void impressionDetected(@NonNull InAppMessage inAppMessage) {
            MessageType messageType = inAppMessage.getMessageType();
    //it doesn't give my key-value data
    //I can't see any methods like getData() which returns an object
        }
    });

2.I also tried creating a FirebaseMessagingService, then also, I didn't get any data:

public class FBMService extends FirebaseMessagingService {

@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
   for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        Log.d(TAG, "key, " + key + " value " + value);
    }
}

}

Here onMessageReceived() itself is not triggered !

adi
  • 984
  • 15
  • 33

1 Answers1

0

I haven't found this documented here, but there is a getData() method inside the InAppMessage class which returns the key-value map ie. the campaign data.

Angad Singh
  • 1,032
  • 1
  • 17
  • 36