首先我为我的英语道歉:-)我正在做一个大项目,我遇到了在我的android应用程序中使用firebase的问题。我有使用分析用户属性的条件的remoteconfig。当我在app中设置用户属性、获取数据,并且成功完成后,激活获取的数据时,我仍然从remoteconfig获取参数的默认值,即使remoteconfig条件为true。代码是用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中的remoteconfig:
参数=测试参数
-myuser=开发
-默认值:=生产
条件:
myuser-如果用户属性testprop与
当我运行这个时,我在控制台中得到这个:
i/toapp:测试参数为生产
我在gradle.build文件中有这些lib:
// 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"
谢谢你的回答。
最佳答案
问题解决了!
在firebase中,我有两个android应用程序(旧应用程序版本和新应用程序版本)。旧应用程序工作正常,但新应用程序出现问题。当我在firebase analytics中打开旧应用程序,然后打开用户属性时,我在远程配置条件中使用了一些参数。当我在Firebase Analytics中将应用程序切换到新版本时,用户属性为空。我在Firebase Analytics中将相同的属性从旧应用程序版本添加到新应用程序版本,新应用程序工作正常。