我正在探索 Firebase 应用内消息,其中当我触发一个事件时,我可以查看我在 Firebase 控制台中设置的横幅/模式对话框。
但是,我在以下路径下看到了在控制台中设置自定义数据的选项:
应用内消息 -> 撰写广告系列 -> 其他选项
所以我设置了如下所示的键值对:
所以,现在我想在我的 android 应用程序中检索这些数据。如何检索数据?
我尝试了以下代码,但没有成功:
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.我也尝试创建一个 FirebaseMessagingService,然后我也没有得到任何数据:
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);
}
}
}
这里 onMessageReceived() 本身没有被触发!