I just started using the Remote Config in the Firebase console. It's a great tool and it works fine, but I can't figure out how I can 'push' different images (drawables) to my app using the parameters in the console. Is this even possible and if yes, how do I use this in my app?
My current 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();
}
}
});
}
}
The remote config defaults:
<?xml version="1.0" encoding="utf-8"?>
<defaultsMap>
<entry>
<key>vernieuwen</key>
<value>true</value>-
</entry>
Can you guys tell me if this is even possible and if so, how that works? Please let me know if you need more information?