Appearance
Mini Program Management
Mini program Management introduces the API for operating mini program, including: open mini program, close mini program, search mini program, etc.
1.Open the mini program
The api used to open the mini program varies from scenario to scenario. Therefore, we offer a variety of different api's for opening mini program.
- Open the online mini program, here you generally only need the mini program id and server address, the api can only open the official and audited version of the mini program.
- QR code to open the mini program, this scenario is to scan the QR code on the mini program platform, get the content in the QR code, and then use that content to open the mini program.The QR code of the mini program of the official version, experience version, audit version, development version and preview version can all be opened using this Api.
- URL Scheme to open mini program, this scenario is to embed the URL Scheme URI in the H5 webpage to trigger the opening of the mini program in the app, only the official version of the mini program on the shelves are supported to open.
1.1 General opening of mini program
When opening an mini program, it will first determine if there is a cached mini program locally, if not, it will automatically download the mini program from the remote server and then open it; if there is a cached mini program, it will first open the local mini program and then check if there is a new version on the server side. If there is a new version, download the new version of the mini program and the next time you open it, it will use the new version of the mini program; if there is no new version, do nothing.
1.1.1 Opening mini program in general
API
kotlin
/**
* Launching mini program via parameter wrapped objects
* @param request Parameter wrapper, including RemoteFinAppletRequest,
QrCodeFinAppletRequest, LocalFinAppletRequest, DecryptFinAppletRequest,
* It is recommended to use the methods IFinAppletRequest.fromAppId,
IFinAppletRequest.fromQrCode, IFinAppletRequest.fromLocal,
Subscribe to DeepL Pro to edit this document.
Visit www.DeepL.com/profor more information.
IFinAppletRequest.fromDecrypt to generate the corresponding request
object.
*/
fun startApplet(context: Context, request: IFinAppletRequest, callback:
FinCallback<String>? = null)
Example of a call to #####
kotlin
FinAppClient.appletApiManager.startApplet(
this,
IFinAppletRequest.fromAppId("apiServer", "appId")
)
java
FinAppClient.INSTANCE.getAppletApiManager().startApplet(
this,
IFinAppletRequest.companion.fromAppId("apiServer", "appId"),
null
);
1.1.2 Carrying launch parameters when opening mini program in general
API
kotlin
/**
* Launching mini program via parameter wrapped objects
* @param request Parameter wrapper, including RemoteFinAppletRequest,
QrCodeFinAppletRequest, LocalFinAppletRequest, DecryptFinAppletRequest,
* It is recommended to use the methods IFinAppletRequest.fromAppId,
IFinAppletRequest.fromQrCode, IFinAppletRequest.fromLocal,
IFinAppletRequest.fromDecrypt to generate the corresponding request
object.
*/
fun startApplet(context: Context, request: IFinAppletRequest, callback:
FinCallback<String>? = null)
Set the start parameters by passing in a RemoteFinAppletRequest object and using the setStartParams method. Example of a call to #####
kotlin
// path is the path to the mini program page
// query is the start parameter, with the content
"key1=value1&key2=value2 ..." in the form of
FinAppClient.appletApiManager.startApplet(
this,
IFinAppletRequest.fromAppId("apiServer", "appId")
.setStartParams(mapOf(
"path" to "/pages/index/index",
"query" to "aaa=test&bbb=123"
))
)
java
Map< String, String> params = new HashMap<>();
// path is the path to the mini program page
params.put("path", "/pages/index/index");
// query is the start parameter, with the content
"key1=value1&key2=value2 ..." in the form of
params.put("query", "aaa=test&bbb=123");
FinAppClient.INSTANCE.getAppletApiManager().startApplet(
this,
IFinAppletRequest.companion.fromAppId("apiServer", "appId")
.setStartParams(params),
null
);
1.2 QR code to open the mini program
Scan the mini program QR code in the platform and pass the content of the parsed mini program QR code to the interface to open the mini program.
API
kotlin
/**
* Launching mini program via parameter wrapped objects
* @param request Parameter wrapper, including RemoteFinAppletRequest,
QrCodeFinAppletRequest, LocalFinAppletRequest, DecryptFinAppletRequest,
* It is recommended to use the methods IFinAppletRequest.fromAppId,
IFinAppletRequest.fromQrCode, IFinAppletRequest.fromLocal,
IFinAppletRequest.fromDecrypt to generate the corresponding request
object.
*/
fun startApplet(context: Context, request: IFinAppletRequest, callback:
FinCallback<String>? = null)
Execute the QR code to open the mini program by passing in the QrCodeFinAppletRequest object. Example of a call to #####
kotlin
FinAppClient.appletApiManager.startApplet(
this,
IFinAppletRequest.fromQrCode("qrCode"),
object : FinSimpleCallback<String>() {
override fun onSuccess(result: String) {
// Successful start-up
}
override fun onError(code: Int, error: String?) {
// Failed to start
}
}
)
java
FinAppClient.INSTANCE.getAppletApiManager().startApplet(
this,
IFinAppletRequest.Companion.fromQrCode("qrCode"),
new FinSimpleCallback< String>() {
@Override
public void onSuccess(String result) {
// Successful start-up
}
@Override
public void onError(int code, String error) {
// Failed to start
}
}
);
:::
1.3 Opening mini program using URL Scheme
The mini program can be opened via URL Schema, which can be opened in a browser or other application with a link such as "finapplet://applet/appid/xxxx". where finapplet is the default schema to add string resources to the app
<string name="fin_applet_router_url_scheme">your schema</string
The default schema can be replaced The full content of the url is schema://applet/appid/{appId}? path=xxx&query=xxx where {appId} is the id of the mini program to be opened The part after ? The latter part is the parameter to open the mini program, the parameter is optional, path is the path to open the mini program, query is the parameter to open, the format is a=1&b=2, because path and query contain special characters, need to be urlencode
1.4 Opening mini program in single process mode
The mini program supports single process mode, which is configured by setting the isSingleProcess property of IFinAppletRequest to true when opening the mini program
/**
* Set whether to open mini program in single process mode
*/
fun setSingleProcess(isSingleProcess: Boolean): IFinAppletRequest
Example of a call
FinAppClient.appletApiManager.startApplet(this,
IFinAppletRequest.fromAppId("xxxx")
.setSingleProcess(true))
The difference between an mini program running in single process mode and multiple processes When the mini program is running in single process mode 1.the mini program will run in the main process and all logic will be executed in the main process.the mini program page will open in the page stack of the main process and follow the page stack of the main process back to the foreground background. When the mini program is closed, the mini program page is closed completely and needs to be restarted when opened again 2.The mini program custom api only needs to be registered with the main process and will also be executed in the main process.Interaction with the main process within the custom api does not require cross-process communication.The interface for registering the api with the mini program process should not be used anymore 3.factory classes exposed by sdk, such as watermarkFactoryClass, offlinePackageFactoryClass, offlineAccountInfoClass will follow the mini program in the main process 4.The context obtained from the custom api is the context of the mini program page, which can jump directly to the app page
2.Close the mini program
As the SDK uses multiple processes to load the mini program, the API does not actually end the mini program, but moves it to the system background.
2.1 Closing the specified mini program
API
kotlin
/**
* :: Close the mini program
*
* @param appId mini program id
*/
fun closeApplet(appId: String)
Example of a call to #####
kotlin
FinAppClient.appletApiManager.closeApplet("appId")
java
FinAppClient.INSTANCE.getAppletApiManager().closeApplet(appId);
:::
2.2 Closing all mini program
API
kotlin
/**
* Close all mini program
*/
fun closeApplets()
Example of a call to #####
kotlin
FinAppClient.appletApiManager.closeApplets()
java
FinAppClient.INSTANCE.getAppletApiManager().closeApplets();
3.Closing the mini program
3.1 Ending the specified mini program
API
kotlin
/**
* Ending a running mini program
*
* @param appId mini program id
*/
fun finishRunningApplet(appId: String)
Example of a call to #####
kotlin
FinAppClient.appletApiManager.finishRunningApplet("appId")
java
FinAppClient.INSTANCE.getAppletApiManager().
finishRunningApplet("appId");
3.2 Ending all mini program
API
kotlin
/**
* End all running mini program
*/
fun finishAllRunningApplets()
Example of a call to #####
kotlin
FinAppClient.appletApiManager.finishAllRunningApplets()
java
FinAppClient.INSTANCE.getAppletApiManager().
finishAllRunningApplets();
4.Delete mini program
Since the mini program package and mini program information will be cached locally, it will be very fast when opened later.
So, if you want to delete all the information of the mini program, then you can call the following api to delete a certain mini program or delete all the mini program, the deletion includes the mini program body, database, files, etc.
4.1 Deleting specified mini program
API
kotlin
/**
* Remove used mini program
*
* @param appId mini program id
*/
fun removeUsedApplet(appId: String)
Example of a call to #####
kotlin
FinAppClient.appletApiManager.removeUsedApplet("appId")
java
FinAppClient.INSTANCE.getAppletApiManager().
removeUsedApplet("appId");
4.2 Delete all mini program
API
kotlin
/**
* :: Clear all applet-related data (databases, files, etc.)
*/
fun clearApplets()
Example of a call to #####
kotlin
FinAppClient.appletApiManager.clearApplets()
java
FinAppClient.INSTANCE.getAppletApiManager().clearApplets();