0
我嘗試從Firebase中的遠程配置中獲取特定值,但它始終爲我提供第一次在客戶端定義的值。從Firebase中提取值Android
這裏是我的代碼:
public static final int DEFAULT_MSG_LENGTH_LIMIT = 1000;
private static final String FRIENDLY_MSG_LENGTH_KEY ="friendly_msg_length";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setDeveloperModeEnabled(BuildConfig.DEBUG).build();
mFirebaseRemoteConfig.setConfigSettings(configSettings);
Map<String, Object> defaultConfigMap = new HashMap<>();
defaultConfigMap.put(FRIENDLY_MSG_LENGTH_KEY, DEFAULT_MSG_LENGTH_LIMIT);
mFirebaseRemoteConfig.setDefaults(defaultConfigMap);
fetchCnfig();
}
private void fetchCnfig() {
long cacheExpiration = 3600;
if(mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()){
cacheExpiration = 0;
}
mFirebaseRemoteConfig.fetch(cacheExpiration)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
mFirebaseRemoteConfig.activateFetched();
applyRetrievedLengthLimit();
}else{
Log.w(TAG, "error fetching config" + task.getException().getMessage());
applyRetrievedLengthLimit();
}
}
});
}
private void applyRetrievedLengthLimit() {
long friendly_msg_length = mFirebaseRemoteConfig.getLong(FRIENDLY_MSG_LENGTH_KEY);
mMessageEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(((int) friendly_msg_length))});
}
任何想法可能是錯誤的將被評估
這樣做的價值,但仍然不會更改從Firebase收到的值 – yaffa