我想要做的是在 Firebase 的 RemoteConfig 中保存 colorPrimay、colorDarkPrimary 等值,这样我就可以从远程配置中更改应用程序的颜色,我做了以下
更新:我要做的是在 Firebase 的 RemoteConfig 中保存 colorPrimay、colorDarkPrimary 等值,以便我可以从远程配置更改应用程序的颜色。我怎么能那样做?
更新:
我尝试过的就像
<--!remote_config_default.xml!-->
<defaultsMap>
<entry>
<key>primaryColor</key>
<value>#9c27b0</value>
</entry>
<entry>
<key>colorPrimaryDark</key>
<value>#7b1fa2</value>
</entry>
<entry>
<key>colorAccent</key>
<value>#FF4081</value>
</entry>
<entry>welcomeMessage</entry>
<value>Connection Failed</value>
像这样取
void applyRemoteConfig() {
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_default);
// cacheExpirationSeconds is set to cacheExpiration here, indicating that any previously
// fetched and cached config would be considered expired because it would have been fetched
// more than cacheExpiration seconds ago. Thus the next fetch would go to the server unless
// throttling is in progress. The default expiration duration is 43200 (12 hours).
int cacheExpiration = 1000;
final String TAG = "Riddles";
mFirebaseRemoteConfig.fetch(cacheExpiration)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "Fetch Succeeded");
// Once the config is successfully fetched it must be activated before newly fetched
// values are returned.
mFirebaseRemoteConfig.activateFetched();
} else {
Log.d(TAG, "Fetch failed");
String message = mFirebaseRemoteConfig.getString("welcomeMessage");
displayWelcomeMessage(message);
Log.d(TAG, message);
}
}
});
String message = mFirebaseRemoteConfig.getString("welcomeMessage");
displayWelcomeMessage(message);
Log.d(TAG, message);
}
但是
mFirebaseRemoteConfig.getString("colorPrimary");
mFirebaseRemoteConfig.getString("colorDarkPrimary");
mFirebaseRemoteConfig.getString("welcomeMessage");
正在返回 Null。