Firebase – 使用userProperty的RemoteConfig返回默认值
首先,我对我的英文表示歉意:-)我正在开发一个大项目,并且在我的Android应用程序中遇到了使用Firebase的问题。 我有使用Analytics(分析)用户属性的条件的RemoteConfig。 当我在应用程序中设置用户属性,获取数据,并成功完成后,我激活提取的数据,即使RemoteConfig条件为true,我仍然从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中的RemoteConfig:
参数= test_param
– MyUser =开发
– 默认值:=生产
条件:
MyUser – 如果用户属性testprop完全匹配一个
当我运行这个,我在控制台中得到这个:
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"
感谢您的答案。
你的代码看起来正确。 这个问题可能是时机。 调用setUserProperty()
,需要一段时间才能将值报告给Firebase服务器,RemoteConfig可以使用该服务器。 我不知道延迟是什么,但可能要一个多小时。 Firebase Analytics会缓存事件数据并不经常发送以减少电池使用情况,如下所述 :
一般来说,您的应用程序记录的事件在大约一个小时的时间内会一起批量上传。 这种方法节省了最终用户设备上的电池,并减少了网络数据的使用。
用户属性很可能以相同的方式处理。 为了测试,您可以启用调试模式以最小的延迟上传数据(如上面的链接所述):
adb shell setprop debug.firebase.analytics.app
我建议你启用调试模式,运行代码setUserProperty()
,等待几分钟,然后运行代码来获取远程配置数据。 当我使用该过程并运行版本11.4.2的Java代码时,它就起作用了。
启用调试模式后,您可以使用Firebase控制台中的Analytics(分析)调试视图来确认您设置的用户属性值已上传到Firebase服务器。
问题解决了!
在Firebase中,我有两个Andorid应用(旧应用版本和新应用版本)。 旧的应用程序工作正常,但与新的应用程序是问题。 当我在Firebase Analytics中打开旧应用程序,然后打开用户属性时,在远程配置条件中使用了一些参数。 当我在Firebase Analytics中将应用切换到新版本时,用户属性为空。 我在Firebase Analytics中将旧应用版本的相同属性添加到新应用版本,新应用正常运行。
- 如何使用Firebase服务器时间戳生成日期?
- 来自firebase的recyclerview onClick getkey
- Android随着日期时间的变化,但是又放了一次,Firebase只是返回过期的令牌
- Firebase @Exclude with kotlin data class
- 移除Firebase侦听器不适用于Android
- Firebase的数据类空构造函数
- Kotlin:不能使用GenericTypeIndicator调用Firebase数据库的getValue
- Firebase Perf不会运行测试应用程序:transformClassesWithFirebasePerformancePluginForDebugAndroidTest
- Firestore本地过滤