Pass startup parameters from the Android client to the default landing page of the Mini Program (pages/index/index). The following procedure uses name and pwd as example parameters.
Prerequisites
Before you begin, ensure that you have accessed the mini program component by referring to Getting started.
Pass startup parameters
-
On the client, add startup parameters to the Mini Program launch call.
Use a
Bundleobject to pass parameters. Setkey="query"to a URI-encoded key-value string, then callstartApp:Bundle param = new Bundle(); String query = "name="+Uri.encode("123")+"&pwd="+Uri.encode("456"); param.putSting("query",query); // set the parameter. MPNebula.startApp(appId:"2020121620201216",param);The startup parameter field is
query. Encode values as key-value pairs (for example,key1=value1&key2=value2), then parse thequeryfield on the Mini Program side to retrieve them.startAppparameters:appId: The Mini Program ID. Find it in the mPaaS console.-
param: ABundleobject containing the startup parameters. Setkey="query"andvalueto a URI-encoded key-value string. Separate multiple parameters with an ampersand (&).ImportantThe Mini Program framework URI-decodes each parameter value. URI-encode your values before passing them.
The Mini Program framework does not process parameter keys. Do not use special characters in keys — the framework may fail to recognize them.
-
In the Mini Program, retrieve the startup parameters from the
optionsargument ofonLaunch/onShow(options).
The
app.jsscript stores the parameters in theglobalDataglobal variable. To use a parameter — such astokenoruser_idpassed from Native in the request header — read or updateglobalDatadirectly from any page in the Mini Program.