All Products
Search
Document Center

Pass startup parameters to Android Mini Program

Last Updated: Apr 06, 2021

In certain scenarios, you need to pass parameters to the default receiving page of the Mini Program, which is pages/index/index. This topic introduces the implementation process of this operation by passing name and pwd parameters as an example.

Prerequisites

You have accessed the mini program component by referring to Quick start.

Procedure

  1. Add parameter information of page redirection during startup on the client. The parameter passing method is as follows:
    1. Bundle param = new Bundle();
    2. String query = "name="+Uri.encode("123")+"&pwd="+Uri.encode("456");
    3. param.putSting("query",query); // set the parameter.
    4. MPNebula.startApp(appId:"2020121620201216",param);
    When the URL starts to pass parameters, the parameter passing field is query. When the Mini Program obtains the parameters, it parses the query field.
    Description of startApp parameter:
    • appId: The Mini Program ID, which can be viewed in the mPaaS console.
    • param: The Bundle object. You can pass request parameters to the Bundle object in the format of key="query",value="Key-value pair". Separate parameters with ampersand (&).
      Notice:
      • The Mini Program framework decodes the value of the key-value pair for each custom input parameter with URI decode function. Therefore, you need to encode the encode the value of the input key-value pair with URI encode function.
      • The Mini Program framework does not process the key of the key-value pair for custom input parameters. Therefore, make sure not to set special characters for the key, otherwise the Mini Program framework may fail to recognize the custom parameters.

2.The Mini Program obtains the parameters. To do this, the Mini Program obtains the parameters from the options parameter of the onLaunch/onShow(options) method.
obtain param
The app.js storage script obtains the parameters passed from the client to the Mini Program and stores them to the globalData global variable. To use these parameters, the Mini Program directly obtains or updates the globalData value. After parameters such as token and user_id in the request header are passed from Native and stored in globalData, the Mini Program directly obtains the globalData value and use the parameters.
app.js