android - Firebase remote config, cant get value. Android
问题描述
I have created some test project for learning Firebase remote config. This is settings in firebase https://monosnap.com/file/0xgQCL7oo7lyOjBs8CG3kZO0szBXh6 . Bellow my code:
final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setDeveloperModeEnabled(BuildConfig.DEBUG)
.build();
config.setConfigSettings(configSettings);
String onlineVersion = FirebaseRemoteConfig.getInstance().getString("android_current_version");// empty string
I dont know why i cant get value from firebase
解决方案
也许您需要先获取远程配置:
config.fetch(cacheExpiration)
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Fetch Succeeded",
Toast.LENGTH_SHORT).show();
// After config data is successfully fetched, it must be activated before newly fetched
// values are returned.
mFirebaseRemoteConfig.activateFetched();
} else {
Toast.makeText(MainActivity.this, "Fetch Failed",
Toast.LENGTH_SHORT).show();
}
String onlineVersion = FirebaseRemoteConfig.getInstance().getString("android_current_version");// empty string
}
})
在“onComplete”方法中,您可以获得远程配置信息
检查这个:远程配置
推荐阅读
- google-apps-script - 创建一个 Table 对象并稍后附加它
- outlook - 在就地存档邮箱中创建项目时出现格式错误的 ID 错误
- javascript - 使用 getScript 异步加载脚本
- mysql - 使用 python 连接到 Synology 数据库
- ffmpeg - ffmpeg 错误 > av_interleaved_write_frame():设备上没有剩余空间
- c# - Process.Start() 导致未经处理的异常,但并非总是如此
- c# - 如何使用反作弊访问游戏的MainModule?
- javascript - Error: Cannot read property 'style' of undefined
- clojure - 具有默认值的选择键
- c# - app.config not getting transformed after installation of nuget package