【发布时间】:2017-10-24 19:52:10
【问题描述】:
首先我为我的英语道歉 :-) 我正在做一个大项目,但在我的 Android 应用程序中使用 Firebase 时遇到了问题。我有条件使用 Analytics 用户属性的 RemoteConfig。当我在应用程序中设置用户属性、获取数据并在成功完成后激活获取的数据时,即使 RemoteConfig 条件为真,我仍然从 RemoteConfig 获取参数的默认值。代码是用 Kotlin 编写的。
这是我的代码示例(此代码在类中的 onCreate() 方法中,它扩展了 Appliaction 类:
FirebaseAnalytics.getInstance(this).setUserProperty("testprop", "a");
FirebaseRemoteConfig.getInstance().fetch(0).addOnCompleteListener {
if (it.isSuccessful) {
FirebaseRemoteConfig.getInstance().activateFetched();
val a = FirebaseRemoteConfig.getInstance().getString("test_param");
Log.i("TOAPP", "Test param is $a");
} else {
Log.i("TOAPP", "Error: ${it.exception?.localizedMessage}");
it.exception?.printStackTrace();
}
}
}
Firebase 中的远程配置:
参数 = test_param
- 我的用户 = 开发
- 默认值:= 生产
条件:
MyUser - 如果 User 属性 testprop 与 a 完全匹配,则适用
当我运行它时,我会在控制台中得到它:
I/TOAPP:测试参数正在生产中
我在 gradle.build 文件中有这些库:
// Play services
implementation "com.google.android.gms:play-services-location:11.4.2"
implementation "com.google.android.gms:play-services-maps:11.4.2"
implementation "com.google.android.gms:play-services-base:11.4.2"
implementation "com.google.android.gms:play-services-identity:11.4.2"
implementation "com.google.android.gms:play-services-places:11.4.2"
// Firebase
implementation "com.google.firebase:firebase-core:11.4.2"
implementation "com.google.firebase:firebase-config:11.4.2"
implementation "com.google.firebase:firebase-messaging:11.4.2"
感谢您的回答。
【问题讨论】:
-
您的帖子(或代码)中有错字吗?在帖子中,描述条件的文本具有属性名称
testprop:如果用户属性 testprop 与 a 完全匹配则适用。在发布的代码中,您正在设置属性testparam。 -
是的,有一个错字...我设置了用户
propertytestprop。我修了帖子。但是代码仍然不起作用。
标签: android firebase firebase-analytics firebase-remote-config