All Products
Search
Document Center

Quick Start

Last Updated: Mar 24, 2021

The HTML5 container and offline packages are supported in the native AAR mode, the mPaaS Inside mode, and the component mode. The HTML5 container allows you to open an online web page in an app, call a native API operation on the frontend, call a custom JSAPI on the frontend, customize the title bar of an HTML5 page, and use the UC kernel. The HTML5 offline package service allows you to publish, preset, start, and update offline packages.

Before you begin

  • If you connect to mPaaS based on native AAR, perform the prerequisite steps and subsequent steps. For more information, see Add mPaaS to your project.
  • If you connect to mPaaS based on mPaaS Inside, complete the access procedure first. For more information, see Access procedure under Connect to mPaaS mPaaS based on mPaaS Inside.
  • If you connect to mPaaS based on components, complete the access procedure first. For more information, see Access procedure under Connect to mPaaS mPaaS based on components.

Add the UC SDK

Native AAR mode

In your project, install the HTML5 container component on the Component Management (AAR) page. For more information, see Manage component dependencies in the native AAR mode.

mPaaS Inside mode

In your project, install the HTML5 container component on the Component Management page.
For more information, see Manage component dependencies in the mPaaS Inside mode.

Component mode

In your Portal and Bundle projects, install the HTML5 container component on the Component Management page.
For more information, see Manage component dependencies in Access procedure.

Initialize the mPaaS

In the native AAR or mPaaS Inside mode, you must initialize the mPaaS.
Add the following code to the Application node:

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

Configure the interval between requests for a Mini Program package

The mPaaS allows you to globally or individually configure the interval between requests for a Mini Program package.

  • Global configuration: In the Android project, create a file named custom_config.json in assets/config and enter the following content in the file:

    1. {
    2. "value": "{\"config\":{\"al\":\"3\",\"pr\":{\"4\":\"86400\",\"common\":\"864000\"},\"ur\":\"1800\",\"fpr\":{\"common\":\"3888000\"}},\"switch\":\"yes\"}",
    3. "key": "h5_nbmngconfig"\
    4. }

    \"ur\":\"1800\" specifies the interval of global updates. The value 1800 is the default value and is measured in seconds. You can modify the value to set the interval between requests for a global offline package. The value ranges from 0 to 86400 seconds, that is, 0 to 24 hours. The value 0 indicates that no intervals are specified.

    Important: Do not modify other parameters unless required.
  • Individual configuration: The configuration takes effect only for the current Mini Program package. In the console, click Add to add an offline package. In the Extension Information field, enter {"asyncReqRate":"1800"} to set the request interval. For more information, see the description of Extension Information in Create an HTML5 offline package.

Check whether the configured request interval takes effect. You can open a project connected to the HTML5 offline package service. Open the log in Logcat, and select the keyword H5BaseAppProvider. If the log contains the following information, the configuration has taken effect.

  1. lastUpdateTime: xxx updateRate: xxx

Use the SDK

The mPaaS Nebula HTML5 container provides a unified API class named MPNebula to implement operations of the HTML5 container and offline packages.

The call process is as follows:

  1. Start an HTML5 offline package.

    • Start an offline package:
      1. /**
      2. * Start an offline package.
      3. *
      4. * @param appId: offline package ID
      5. */
      6. public static void startApp(String appId);
    • Start an offline package with startup parameters:
      1. /**
      2. * Start an offline package.
      3. *
      4. * @param appId: offline package ID
      5. * @param params: startup parameters
      6. */
      7. public static void startApp(String appId, Bundle params);
  2. Start an online page.

    • Start an online page:
      1. /**
      2. * Start an online URL.
      3. *
      4. * @param url: online URL
      5. */
      6. public static void startUrl(String url)
    • Start an online page with startup parameters:
      1. /**
      2. * Start an online URL.
      3. *
      4. * @param url: online URL
      5. * @param param: sartup parameters
      6. */
      7. public static void startUrl(String url, Bundle param);
  3. Set a custom UserAgent.

    1. Implement a UA setter.
      1. public class H5UaProviderImpl implements H5UaProvider {
      2. @Override
      3. public String getUa(String defaultUaStr) {
      4. // Do not modify the defaultUaStr parameter or return a result that does not contain the defaultUaStr parameter.
      5. return defaultUaStr + " AlipayClient/mPaaS";
      6. }
      7. }
    2. Call the UA setup API:
      1. /**
      2. *Set UA.
      3. *
      4. * @param uaProvider: UA setter. The getUa method needs to be implemented.
      5. */
      6. public static void setUa(H5UaProvider uaProvider)
    3. Perform setting as follows:
      1. MPNebula.setUa(new H5UaProviderImpl());
  4. Set a custom container view.

    The container provides methods for setting a custom title bar, navigation menu, the header of pull-to-refresh, and the WebView layout. For more information, see Sample code.

    1. Implement a view setter.

      1. public class H5ViewProviderImpl implements H5ViewProvider {
      2. @Override
      3. public H5WebContentView createWebContentView(Context context) {
      4. // The custom layout of WebView is returned here. If null is returned, the default view takes effect.
      5. return null;
      6. }
      7. @Override
      8. public H5TitleView createTitleView(Context context) {
      9. // The custom title bar is returned here. If null is returned, the default view takes effect.
      10. return null;
      11. }
      12. @Override
      13. public H5PullHeaderView createPullHeaderView(Context context, ViewGroup viewGroup) {
      14. // The pull-to-refresh head is returned here. If null is returned, the default view takes effect.
      15. return null;
      16. }
      17. @Override
      18. public H5NavMenuView createNavMenu() {
      19. // The custom navigation menu is returned here. If null is returned, the default view takes effect.
      20. return null;
      21. }
      22. }
    2. Call the view setup API:
      1. /**
      2. *Set container related custom views, such as the title bar, menu bar, web layout, and slide-the pull-down refresh head view.
      3. * @param viewProvider: custom view provider
      4. */
      5. public static void setCustomViewProvider(H5ViewProvider viewProvider);
    3. Set the custom views.
      1. MPNebula.setCustomViewProvider(new H5ViewProviderImpl());
      Note: To set a custom title bar, set the bundle name first. Otherwise, the resource cannot be found.
      1. // Set the name of the bundle where the title bar resource resides. If it is not set, the resource cannot be loaded and the title bar cannot take effect.
      2. H5Utils.setProvider(H5ReplaceResourceProvider.class.getName(), new H5ReplaceResourceProvider() {
      3. @Override
      4. public String getReplaceResourcesBundleName() {
      5. return BuildConfig.BUNDLE_NAME;
      6. }
      7. });
      8. MPNebula.setCustomViewProvider(new H5ViewProviderImpl());
  5. Embed the view of a single container into the page.

    Select one or more of the following methods as required to embed the HTML5 page into the view of a single container. The API provides synchronous and asynchronous methods.

    • Synchronous method

      1. /**
      2. *Obtain the view of the HTML5 container.
      3. *
      4. * @param activity: page context
      5. * @param param: startup parameters, where the app ID or URL may be included
      6. * @return: view of the HTML5 container
      7. */
      8. public static View getH5View(Activity activity, Bundle param);
    • Asynchronous method

      1. /**
      2. *Obtain the view of the HTML5 container asynchronously.
      3. *
      4. * @param activity: page context
      5. * @param param: startup parameters, where the app ID or URL may be included
      6. * @param h5PageReadyListener: asynchronous callback
      7. */
      8. public static void getH5ViewAsync(Activity activity, Bundle param, H5PageReadyListener h5PageReadyListener);
      Note:
      • Before you embed the HTML5 page by using the synchronous method or the asynchronous method, obtain the information about the offline package.
      • When you use the asynchronous method, the main threshold is not occupied and therefore performance is not affected.

Use the HTML5 container

To use the features of the HTML5 container, see Use the HTML5 container.

Use HTML5 offline packages

To use the features of the HTML5 offline package service, see Use HTML5 offline packages.