|
11 | 11 | import com.google.android.gms.tasks.OnCompleteListener; |
12 | 12 | import com.google.android.gms.tasks.Task; |
13 | 13 | import com.google.firebase.quickstart.config.R; |
| 14 | +import com.google.firebase.remoteconfig.ConfigUpdate; |
| 15 | +import com.google.firebase.remoteconfig.ConfigUpdateListener; |
14 | 16 | import com.google.firebase.remoteconfig.FirebaseRemoteConfig; |
| 17 | +import com.google.firebase.remoteconfig.FirebaseRemoteConfigException; |
15 | 18 | import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings; |
16 | 19 |
|
17 | 20 | public class MainActivity extends AppCompatActivity { |
@@ -58,6 +61,24 @@ public void onComplete(@NonNull Task<Boolean> task) { |
58 | 61 | } |
59 | 62 | }); |
60 | 63 | // [END fetch_config_with_callback] |
| 64 | + |
| 65 | + // [START add_config_update_listener] |
| 66 | + mFirebaseRemoteConfig.addOnConfigUpdateListener(object :ConfigUpdateListener { |
| 67 | + override fun onUpdate(configUpdate :ConfigUpdate) { |
| 68 | + Log.d(TAG, "Updated keys: " + configUpdate.updatedKeys.joinToString(", ")); |
| 69 | + |
| 70 | + if (configUpdate.updatedKeys.contains("welcome_message")) { |
| 71 | + remoteConfig.activate().addOnCompleteListener { |
| 72 | + displayWelcomeMessage() |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + override fun onError(error:FirebaseRemoteConfigException) { |
| 78 | + Log.w(TAG, "Config Update Error Code: " + error.code, error) |
| 79 | + } |
| 80 | + }) |
| 81 | + // [END add_config_update_listener] |
61 | 82 | } |
62 | 83 |
|
63 | 84 | private void displayWelcomeMessage() { |
|
0 commit comments