All Products
Search
Document Center

Quick start

Last Updated: Apr 20, 2021

You can access Mini Program SDK to Android client through Native AAR, mPaaS Inside or Portal & Bundle accessing method. For more information, see the Accessing method introduction.

Note: Mini Program is only available in 10.1.60 and higher baseline versions.

This section introduces how to use Mini Program in combination with the official Demo.

If you encounter problems during accessing the Mini Program, please scan the QR code with DingTalk to join the Mini program question answering group for consultation.

Prerequisites

Native AAR

  1. Add the mPaaS to your project.
  2. Add the Mini Program dependency. Install the Mini Program component through mPaaS Component Management (AAR) in the project.

mPaaS Inside

  1. Complete the mPaaS Inside access process.
  2. Add the Mini Program dependency. Install the Mini Program component through mPaaS Component Management in the project. For more information, see Manage component dependencies.

Portal & Bundle

  1. Complete the mPaaS Portal & Bundle access process.
  2. Add the Mini Program dependency. Install the Mini Program component through mPaaS Component Management in the Portal and Bundle projects. For more information, see Manage component dependencies.

Procedure

The procedure of accessing Mini Program contains the following steps:

  1. Initialize configuration
    1. Initialize mPaaS
    2. Configure mini program signature verification
    3. Configure AndroidManifest
    4. Apply for UC kernel
  2. Release a mini program
    1. Enter the mini program background
    2. Configure virtual domain name
    3. Create a mini program
    4. Release the mini program
  3. Start the mini program

1. Initialize configuration

1.1 Initialize mPaaS

If you access Mini Program through Native AAR or mPaaS Inside, you need to initialize mPaaS.You need to add the following code in MyApplication:

  1. public class MyApplication extends Application {
  2. @Override
  3. protected void attachBaseContext(Context base) {
  4. super.attachBaseContext(base);
  5. // mPaaS initialization callback
  6. QuinoxlessFramework.setup(this, new IInitCallback() {
  7. @Override
  8. public void onPostInit() {
  9. // Initialize the mini program public resource package
  10. H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(),new TinyAppCenterPresetProvider());
  11. }
  12. });
  13. }
  14. @Override
  15. public void onCreate() {
  16. super.onCreate();
  17. // Initialize mPaaS
  18. QuinoxlessFramework.init();
  19. }
  20. }

In onPostInit, the public resource packages are set as follows:

  1. H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(),new TinyAppCenterPresetProvider());

If you cannot find the class TinyAppCenterPresetProvider, it may be that your baseline version is less than 10.1.68.7, please refer to Mini Program base library to process it.

1.2 Configure mini program signature verification

Create the file custom_config.json under the pathassets/config in the Android project, and enter the following content in the file.

  1. [
  2. {
  3. "value": "NO",
  4. "key": "h5_shouldverifyapp"
  5. }
  6. ]

As for the value, “NO” means disabling the Mini Program signature verification while “YES” for enabling the Mini Program signature verification. It defaults to “YES” in case of no input. In the development and debugging stage, it is suggested to enable signature verification. For specific operations, see Configure mini program packages.

Configure the time interval for requesting mini program packages

mPaaS supports configuring the time interval for requesting mini program packages. You can set the time interval globally or individually.

  • Global setting: You can add the following code in custom_config.json:

    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\" defines the global update interval, where 1800 is the default value, representing the time length in seconds. You can modify this value to set your global mini program package request interval which can be in the range of 0 ~ 86,400 seconds (namely 0 ~ 24 hours), and 0 means there is no limit on the request interval.

    Important: Do not modify other parameters at will.
  • Individual setting: The interval setting only works on the current mini program package. You can log in to the mPaaS console, go to the Add Mini Program package > Extended information page, and fill in {"asyncReqRate":"1800"} to set the request time interval. For details, see the extended information in Create a mini program package.

Verify

Verify if the time interval configuration works. You can open a project that has accessed the Mini Program, and filter the keyword “H5BaseAppProvider” in the logcat log. If you can find the following information, it means the configuration has taken effect.

  1. lastUpdateTime: xxx updateRate: xxx

1.3 Configure AndroidManifest

If you access Mini Program through Native AAR, you need to add the following configuration in AndroidManifest.xml.

  1. <application>
  2. ···
  3. <meta-data android:name="nebula.android.meta.enable" android:value="true"/>
  4. ···
  5. </application>

1.4 Apply for UC kernel

Before using the Mini Program, you need to apply for and configure the UC kernel. For specific operations, refer to Apply for UC Kernel.

UC kernel endows Mini Program with the same-layer processing capability, such as embedding webview and embedding map, and gives it a better rendering experience.

2. Release a mini program

Before starting the mini program, you must release the mini program through the mPaaS console.

2.1 Enter the mini program background

Log in to the mPaaS console, and enter the Mini Program > Release Mini Program page from the left navigation pane.

2.2 Configure virtual domain name

If you are using Mini Program for the first time, please go to the Mini Program > Release Mini Program > Manage configuration page and configure the virtual domain name first. You can set any domain name. It is recommended to use your corporate domain name, such as test.com.

2.3 Create a mini program

Enter the mPaaS console, and complete the following steps:

  1. Click the Mini Program > Release Mini Program menu from the left navigation pane.
  2. On the mini program list page, click New.
  3. In the New Mini Program window, fill in the mini program ID and name, then click Submit. The mini program ID is a 16-digit number, for example 2018080616290001.
  4. In the mini program list, find the new mini program and click Add.
  5. In the Basic Information column, complete the following configuration:

    • Version: Fill in the version number of the mini program package, for example 1.0.0.0.
    • Client version range: Select the applicable Android client version range for the mini program. Only when the App is in the version range, can the Mini Program start, otherwise it cannot start. The minimum version can be 0.0.0 while the maximum version can be left empty. In such case, the Mini Program can start in the Android client of all versions.

      Note: Ensure that the version is of the Android client, not the mini program.
    • Icon: Click Select a file to upload the icon of the mini program package. The icon is required when you create the mini program package for the first time. For example:

    • File: Upload the mini program package resource file which must be a .zip file. There is an mPaaS Mini Program demo for you (click here to download), you can upload it directly.

      Note: Before you upload the .zip file, you should rename the zip file and the file in the zip to the 16-digit ID of your mini program.
  6. In the Configuration information column, complete the following configuration:

    • Main entry URL: Required. It is the first page of the mini program package, in the format of “/index.html#xxx/xxx/xxx/xxx”, where “xxx/xxx/xxx/xxx” behind “#” is the first value in “pages” in the app.json of the mini program. As shown in the figure below, the main entrance of the mPaaS Mini Program demo is “/index.html#page/tabBar/component/index”.

      3

    • As for the remaining configurations, keep the default setting.

  7. Check I have confirmed that the above information is accurate and will not be modified once submitted.
  8. Click Submit.

2.4 Release the mini program

  1. Enter the Mini Program > Release Mini Program > Manage official package page from the left navigation pane.
  2. On the mini program list page, select the target Mini Program and corresponding version, click Create release task.
  3. In the release task creation column, complete the following settings:
    • Release type: select Official.
    • Release description: Optional
  4. Click OK to complete the release task creation.

3 Start the mini program

After finishing the above steps, you can execute the following code in the Android project to start the demo mini program.

  1. MPNebula.startApp("2018080616290001");
Note: The 2018080616290001 in the code refers to the mini program ID. The ID here is fore reference only, you should enter the actual program ID in practice.