Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase remote config, cant get value. Android

I have created some test project for learning Firebase remote config. This is settings in firebase https://monosnap.com/file/0xgQCL7oo7lyOjBs8CG3kZO0szBXh6 . Bellow my code:

final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
            FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
                    .setDeveloperModeEnabled(BuildConfig.DEBUG)
                    .build();
            config.setConfigSettings(configSettings);

            String onlineVersion = FirebaseRemoteConfig.getInstance().getString("android_current_version");// empty string

I dont know why i cant get value from firebase

like image 585
r1299597 Avatar asked Mar 13 '26 23:03

r1299597


1 Answers

Maybe you need to fetch the remote config first:

config.fetch(cacheExpiration)
    .addOnCompleteListener(this, new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                Toast.makeText(MainActivity.this, "Fetch Succeeded",
                        Toast.LENGTH_SHORT).show();

                // After config data is successfully fetched, it must be activated before newly fetched
                // values are returned.
                mFirebaseRemoteConfig.activateFetched();

            } else {
                Toast.makeText(MainActivity.this, "Fetch Failed",
                        Toast.LENGTH_SHORT).show();
            }

            String onlineVersion = FirebaseRemoteConfig.getInstance().getString("android_current_version");// empty string
        }
    })

In the "onComplete" method, you can get the remote config info

check this: Remote Config

like image 96
Max Pinto Avatar answered Mar 15 '26 12:03

Max Pinto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!