我刚开始在Firebase控制台中使用远程配置。它是一个很好的工具,它工作正常,但我无法弄清楚我是如何推动'使用控制台中的参数将不同的图像(drawables)添加到我的应用程序中。这是否可能,如果是,我如何在我的应用程序中使用它?
我目前的主要活动:
public class MainActivity extends AppCompatActivity {
private static final String TEAM1 = "team1";
private static final String TEAM2 = "team2";
private FirebaseRemoteConfig mFirebaseRemoteConfig;
private TextView mTeam1Text;
private TextView mTeam2Text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTeam1Text = (TextView) findViewById(R.id.team1);
mTeam2Text = (TextView) findViewById(R.id.team2);
Button fetchButton = (Button) findViewById(R.id.button);
fetchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fetchDiscount();
}
});
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setDeveloperModeEnabled(BuildConfig.DEBUG)
.build();
mFirebaseRemoteConfig.setConfigSettings(configSettings);
mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults);
fetchDiscount();
}
private void fetchDiscount() {
mTeam1Text.setText(mFirebaseRemoteConfig.getString(TEAM1));
mTeam2Text.setText(mFirebaseRemoteConfig.getString(TEAM2));
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()) {
Toast.makeText(MainActivity.this, "Vernieuwd",
Toast.LENGTH_SHORT).show();
mFirebaseRemoteConfig.activateFetched();
} else {
Toast.makeText(MainActivity.this, "Vernieuwen mislukt",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
远程配置默认为:
<?xml version="1.0" encoding="utf-8"?>
<defaultsMap>
<entry>
<key>vernieuwen</key>
<value>true</value>-
</entry>
答案 0 :(得分:1)
Firebase远程配置用于向您的应用发送简单值。它不能用于传送图像。
处理此方案的典型方法是将图像与远程配置分开。例如:您可以将它们存储在Firebase存储或Firebase托管中。
然后在远程配置中,您将拥有一个参数,其中包含要显示的图像的URL:
.nav_panel {
overflow: auto;
height: 100%;
}