Skip to content

Applet Management

Applet Management introduces the API for operating applets, including: open applet, close applet, search applet, etc.

1.Open the applet

The api used to open the applet varies from scenario to scenario. Therefore, we offer a variety of different api's for opening applets.

  1. Open the online applet, here you generally only need the applet id and server address, the api can only open the official and audited version of the applet.
  2. QR code to open the applet, this scenario is to scan the QR code on the applet platform, get the content in the QR code, and then use that content to open the applet.The QR code of the applet of the official version, experience version, audit version, development version and preview version can all be opened using this Api.
  3. URL Scheme to open applets, this scenario is to embed the URL Scheme URI in the H5 webpage to trigger the opening of the applets in the app, only the official version of the applets on the shelves are supported to open.

1.1 General opening of applets

When opening an applet, it will first determine if there is a cached applet locally, if not, it will automatically download the applet from the remote server and then open it; if there is a cached applet, it will first open the local applet 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 applet and the next time you open it, it will use the new version of the applet; if there is no new version, do nothing.

1.1.1 Opening applets in general

API
kotlin
/**
* Launching applets 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 ##### :::: tabs ::: tab "Kotlin"

kotlin
FinAppClient.appletApiManager.startApplet(
 this,
 IFinAppletRequest.fromAppId("apiServer", "appId")
)

:::

::: tab "Java"

java
FinAppClient.INSTANCE.getAppletApiManager().startApplet(
 this,
 IFinAppletRequest.companion.fromAppId("apiServer", "appId"),
 null
);

::: ::::

1.1.2 Carrying launch parameters when opening applets in general

API
kotlin
/**
* Launching applets 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 ##### :::: tabs ::: tab "Kotlin"

kotlin
// path is the path to the applet 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"
 ))
)

:::

::: tab "Java"

java
Map< String, String> params = new HashMap<>();
// path is the path to the applet 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 applet

Scan the applet QR code in the platform and pass the content of the parsed applet QR code to the interface to open the applet.

API
kotlin
/**
* Launching applets 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 applet by passing in the QrCodeFinAppletRequest object. Example of a call to ##### :::: tabs ::: tab "Kotlin"

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
 }
 }
)

:::

::: tab "Java"

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 applets using URL Scheme

The applet 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 applet to be opened The part after ? The latter part is the parameter to open the applet, the parameter is optional, path is the path to open the applet, 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 applets in single process mode

The applet supports single process mode, which is configured by setting the isSingleProcess property of IFinAppletRequest to true when opening the applet

 /**
* Set whether to open applets 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 applet running in single process mode and multiple processes When the applet is running in single process mode 1.the applet will run in the main process and all logic will be executed in the main process.the applet 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 applet is closed, the applet page is closed completely and needs to be restarted when opened again 2.The applet 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 applet process should not be used anymore 3.factory classes exposed by sdk, such as watermarkFactoryClass, offlinePackageFactoryClass, offlineAccountInfoClass will follow the applet in the main process 4.The context obtained from the custom api is the context of the applet page, which can jump directly to the app page

2.Close the applet

As the SDK uses multiple processes to load the applet, the API does not actually end the applet, but moves it to the system background.

2.1 Closing the specified applet

API
kotlin
/**
* :: Close the applet
*
* @param appId applet id
*/
fun closeApplet(appId: String)

Example of a call to ##### :::: tabs ::: tab "Kotlin"

kotlin
FinAppClient.appletApiManager.closeApplet("appId")

:::

::: tab "Java"

java
FinAppClient.INSTANCE.getAppletApiManager().closeApplet(appId);

::: ::::

2.2 Closing all applets

API
kotlin
/**
* Close all applets
*/
fun closeApplets()

Example of a call to ##### :::: tabs ::: tab "Kotlin"

kotlin
FinAppClient.appletApiManager.closeApplets()

:::

::: tab "Java"

java
FinAppClient.INSTANCE.getAppletApiManager().closeApplets();

::: ::::

3.Closing the applet

3.1 Ending the specified applet

API
kotlin
/**
* Ending a running applet
*
* @param appId applet id
*/
fun finishRunningApplet(appId: String)

Example of a call to ##### :::: tabs ::: tab "Kotlin"

kotlin
FinAppClient.appletApiManager.finishRunningApplet("appId")

:::

::: tab "Java"

java
FinAppClient.INSTANCE.getAppletApiManager().
finishRunningApplet("appId");

::: ::::

3.2 Ending all applets

API
kotlin
/**
* End all running applets
*/
fun finishAllRunningApplets()

Example of a call to ##### :::: tabs ::: tab "Kotlin"

kotlin
FinAppClient.appletApiManager.finishAllRunningApplets()

:::

::: tab "Java"

java
FinAppClient.INSTANCE.getAppletApiManager().
finishAllRunningApplets();

::: ::::

4.Delete applets

Since the applet package and applet information will be cached locally, it will be very fast when opened later.

So, if you want to delete all the information of the applet, then you can call the following api to delete a certain applet or delete all the applets, the deletion includes the applet body, database, files, etc.

4.1 Deleting specified applets

API
kotlin
/**
* Remove used applets
*
* @param appId applet id
*/
fun removeUsedApplet(appId: String)

Example of a call to ##### :::: tabs ::: tab "Kotlin"

kotlin
FinAppClient.appletApiManager.removeUsedApplet("appId")

:::

::: tab "Java"

java
FinAppClient.INSTANCE.getAppletApiManager().
removeUsedApplet("appId");

::: ::::

4.2 Delete all applets

API
kotlin
/**
* :: Clear all applet-related data (databases, files, etc.)
*/
fun clearApplets()

Example of a call to ##### :::: tabs ::: tab "Kotlin"

kotlin
FinAppClient.appletApiManager.clearApplets()

:::

::: tab "Java"

java
FinAppClient.INSTANCE.getAppletApiManager().clearApplets();

::: ::::