相关文章推荐
大方的沙发  ·  Android OpenGL ...·  9 月前    · 
文雅的香槟  ·  How To Run CMD ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Thats my MainActivity:

final private FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
protected void onCreate(Bundle savedInstanceState) {
    //..code..
    //fetch from Firebase
    fetchAll();
private void fetchAll(){
     final FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(BuildConfig.DEBUG)
            .build();
    mFirebaseRemoteConfig.setConfigSettings(configSettings);
    mFirebaseRemoteConfig.setDefaults(R.xml.defaults);
    mFirebaseRemoteConfig.fetch()
            .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();
                        mFirebaseRemoteConfig.activateFetched();
                    }else{
                        Toast.makeText(MainActivity.this, "Fetch Failed",
                                Toast.LENGTH_SHORT).show();
                    displayWelcomeMessage();
private void displayWelcomeMessage(){
    String welcomeMessage = mFirebaseRemoteConfig.getString("textView_send_text");
    Toast.makeText(this, welcomeMessage,
            Toast.LENGTH_SHORT).show();

Toast output:

So Toast gets the value from xml/defaults not from the Cloud. It'd be much appreciated if somebody found where I made a mistake.

For development testing, specify a cache expiration time of zero to force an immediate fetch:

mFirebaseRemoteConfig.fetch(0) // <- add the zero
        .addOnCompleteListener(this, new OnCompleteListener<Void>() {
                dont do it too many times or you'll have a exception. i recommend the emulator so you can switch a few times if you reach the throttle limit.
– j2emanue
                Sep 15, 2017 at 2:12
                Though it solves a problem, after several launches an application stops getting OnCompleteListener events.
– CoolMind
                Feb 1, 2019 at 12:49

Some tips the helped to me:

  • Don't forget to click "publish changes" in Firebase console after each value update
  • Uninstall and install the App before checking (Firebase may not fetch immediately)
  • Use mFirebaseRemoteConfig.fetch(0)
  • Reinstalling also worked for me. Can you please explain why reinstall is required? How can i make sure it is indeed updated without reinstall in production? – 4ntoine Jan 2, 2021 at 9:46 @4ntoine reinstall required when you testing your app, since you don't want to wait. remote config will be updated in production, but not immediately – Pavel Poley Jan 2, 2021 at 10:29

    For what it worth I found that our firebase remote configs weren't downloading no matter what we tried - we are usually debugging while connected to a proxy (like Charles Proxy) and that was interrupting the firebase cloud update.

    Once we connected to a non-proxied wifi connection we got the update.

    You can also set your config to developer mode if running a debug build which will refresh values more often - but the proxy was our root problem.

    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
                .setDeveloperModeEnabled(BuildConfig.DEBUG)
                .build();
                    Were you ever able to find a solution for remote config while proxying? We were already enabling developer mode.
    – flopshot
                    Feb 14, 2019 at 19:45
    

    In Flutter, I just changed the value of minimumFetchInterval to const Duration(hours: 0). I manually added an message to firebase and here I just get it. Here is my code;

        await Firebase.initializeApp();
        RemoteConfig remoteConfig = RemoteConfig.instance;
        await remoteConfig.setConfigSettings(RemoteConfigSettings(
          fetchTimeout: const Duration(seconds: 10),
          minimumFetchInterval: const Duration(hours: 0),
        RemoteConfigValue(null, ValueSource.valueStatic);
        bool updated = await remoteConfig.fetchAndActivate();
        if (updated) {
          print("it is updated");
        } else {
          print("it is not updated");
        print('my_message ${remoteConfig.getString('my_message')}');
    

    There is a default minimum time duration Intervals for firebase remote config fetching. According to the Firebase documentation, it is now 12 hours. During that default time interval gap, if you change the keys from Firebase remote config and if you don't uninstall the app, you don't get updated data. you will get updated data after passing default time intervals. If you need more frequent data changes, you can override fetch intervals from client side.

    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Abhishek Dutt Mar 17, 2022 at 15:22

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.