All Products
Search
Document Center

Access Android

Last Updated: May 25, 2021

The switch configuration service enables a client to dynamically modify the processing logic in the client code without releasing a new client version. The client controls related processing based on the switch value dynamically obtained from the backend. With the switch configuration service, you can configure, modify, and push various switches. A switch is a key-value pair.

This topic briefly describes how to fast integrate the switch configuration function to the Android client. Currently, you can access switch configuration function through Native AAR, mPaaS Inside, or Portal & Bundle.

The complete access process mainly includes the following 3 steps:

  1. Add SDK
  2. Initialize mPaaS (only required for Native AAR and mPaaS Inside)
  3. Use the SDK

Prerequisites

Add SDK

Native AAR mode

Follow the instructions in AAR component management to install the CONFIGSERVICE component in the project through Component management (AAR).

mPaaS Inside mode

Install the CONFIGSERVICE component in the project through Component management (AAR).

For more information, see Manage component dependencies > Add/delete component dependencies.

Componentized access mode

Install the CONFIGSERVICE component in the Portal and Bundle projects through Component management (AAR).

For more information, see Manage component dependencies > Add/delete component dependencies.

Initialize mPaaS

If you access MAS through Native AAR or mPaaS Inside, you must initialize mPaaS.

Add the following codes in the object Application:

 
  1. public class MyApplication extends Application {
  2. @Override
  3. protected void attachBaseContext(Context base) {
  4. super.attachBaseContext(base);
  5. // Set mPaaS initialization callback
  6. QuinoxlessFramework.setup(this, new IInitCallback() {
  7. @Override
  8. public void onPostInit() {
  9. //This callback indicates that mPaaS initialization has been done, and relevant mPaaS calls can be performed here
  10. }
  11. });
  12. }
  13. @Override
  14. public void onCreate() {
  15. super.onCreate();
  16. // Initialize mPaaS
  17. QuinoxlessFramework.init();
  18. }
  19. }

Use the SDK

mPaaS provides the switch configuration management API MPConfigService to implement switch configuration.

Complete the following steps to implement switch configuration:

  1. In the mPaaS console, go to the Mobile Delivery > Manage configuration page, add desired switch configuration items, and set them based on information such as the platform, whitelist, percentage, version number, model, and Android version. For more information, see Configuration management.
  2. After a switch key is released in the console, the client can call the specified API to obtain the value of the switch key.

    The switch configuration management API MPConfigService provides many APIs externally. You can understand the function of each API based on its name. The following lists the APIs:

       
    1. public class MPConfigService {
    2. /**
    3. * Obtain switch configurations
    4. *
    5. * @param key
    6. * @return
    7. */
    8. public static String getConfig(String key);
    9. /**
    10. * Load switch configurations. The latest switch configurations are obtained every half an hour by default.
    11. */
    12. public static void loadConfig();
    13. /**
    14. * Load switch configurations immediately.
    15. *
    16. * @param delay Delay after which switch configurations are loaded, in ms. 0 indicates that switch configurations are loaded immediately.
    17. */
    18. public static void loadConfigImmediately(long delay);
    19. /**
    20. * Register a listener for listening to switch configuration changes.
    21. * @param configChangeListener listener
    22. * @return
    23. */
    24. public static boolean addConfigChangeListener(ConfigService.ConfigChangeListener configChangeListener);
    25. /**
    26. * Remove the listener for listening to switch configuration changes
    27. * @param configChangeListener listener
    28. */
    29. public static void removeConfigChangeListener(ConfigService.ConfigChangeListener configChangeListener);
    30. }