0
我剛剛開始使用Firebase控制檯中的遠程配置。這是一個很好的工具,它工作正常,但我無法弄清楚如何使用控制檯中的參數將不同的圖像(可繪製)「推送」到我的應用程序。這是甚至可能的,如果是的話,我該如何在我的應用程序中使用它?使用Firebase遠程配置顯示圖像
我現在的MainActivity:
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>
你們能告訴我,如果這甚至有可能,如果是這樣,那是如何工作的?請讓我知道你是否需要更多信息?