Skip to content

Callback Methods

Part of the business in the mini program is defined in the abstract, and these abstractions are exposed to the outside world in the form of interfaces, which can implement the specific business logic themselves. These proxy methods are declared in abstract classes such as [IAppletHandler], [IAppletProcessHandler], etc.

1. IAppletHandler

Part of the abstract business is defined in IAppletHandler, the application can pass the instance of IAppletHandler to the SDK by calling setAppletHandler of IAppletApiManager, when the business is triggered, the SDK will call back to the external via the IAppletHandler When the business is triggered, the SDK will call back to the external world via the corresponding method of IAppletHandler to execute the specific business logic implemented by the external world.

kotlin
/**
 * :: Mini programs abstract business callback interfaces, and the SDK
exposes these abstractions to external parties in the form of
interfaces, which are implemented concretely by external parties
*/
interface IAppletHandler {

 interface IAppletCallback {
 /**
* Success callback
*/
 fun onSuccess(result: JSONObject? = null)
 /**
* Failure to call back
*/
 fun onFailure()
 /**
* Cancel callbacks
*/
Subscribe to DeepL Pro to edit this document.
Visit www.DeepL.com/profor more information.
 fun onCancel()
 }
 /**
* Forwarding mini program
*
* @param appInfo mini program information, a string of json containing
information such as mini program id, mini program name, mini program icon, user id, and
the content of the data forwarded.
* The content of [appInfo] is in the following format.
* {
* "appTitle": "Vantaa mini program",
* "appAvatar":
"https:\/\/www.finogeeks.club\/statics\/images\/swan_mini\/swan_logo.pn
g",
* "appId": "5df36b3f687c5c00013e9fd1",
* "appType": "trial",
* "userId": "finogeeks",
* "cryptInfo":
"SFODj9IW1ENO8OA0El8P79aMuxB1DJvfKenZd7hrnemVCNcJ+Uj9PzkRkf/Pu5nMz0cGjj
0Ne4fcchBRCmJO+
As0XFqMrOclsqrXaogsaUPq2jJKCCao03vI8rkHilrWxSDdzopz1ifJCgFC9d6v29m9jU29
wTxlHsQUtKsk/wz0BROa+aDGWh0rKvUEPgo8mB+40/
zZFNsRZ0PjsQsi7GdLg8p4igKyRYtRgOxUq37wgDU4Ymn/yeXvOv7KrzUT",
* "params": {
* "title": "apt-test-tweet-Interface-test-released-dynamics! @#$
%......&*(",
* "desc": "Service Experts by Your Side",
* "imageUrl": "finfile:\/\/tmp_fc15edd8-2ff6-4c54-9ee9-
fe5ee034033d1576550313667.png",
* "path": "pages\/tweet\/tweet-detail.html?fcid=
%40staff_staff1%3A000000.finogeeks.com&timelineId=db0c2098-031e-41c4-
b9c6- 87a5bbcf681d&shareId=3dfa2f78-19fc-42fc-b3a9-4779a6dac654",
* "appInfo": {
* "weixin": {
* "path":"\/studio\/pages\/tweet\/tweet-detail",
* "query": {
* "fcid":"@staff_staff1:000000.finogeeks.com",
* "timelineId": "db0c2098-031e-41c4-b9c6-87a5bbcf681d"
* }
* }
* }
* }
* }
* Description of the fields in [appInfo].
* appId mini program ID
* appTitle mini program name
* appAvatar mini program avatar
* appType mini program type, where trial means experience, temporary
means temporary, review means review, release means online and
development means development
* userId User ID
* cryptInfo mini program encryption information
* other parameters attached to params, passed by the mini program itself
*
* @param bitmap The mini program cover image. If the
[appInfo].params.imageUrl field is a link address of http, https, then
the mini program cover image
* Just take the image corresponding to [appInfo].params.imageUrl,
otherwise the cover image of the mini program is taken as [bitmap].
*/
 fun shareAppMessage(appInfo: String, bitmap: Bitmap?, callback:
IAppletCallback)
 /**
* :: Obtaining user information
*
* @return UserInfo[Map]
*/
 fun getUserInfo(): Map<String, String>
 /**
* :: Obtain the user's mobile phone number
* Information is returned via callbacks in json format, generally
in the following format.
* {"phone": "xxxxxxxxxxxx"}
*/
 override fun getPhoneNumber(callback:
IAppletHandler.IAppletCallback) {
 callback.onSuccess(JSONObject().put("phone", "xxxxxxxxxxxx"))
 }
 /**
 * :: Return to the host app page event from the mini program page, with
the host app implementing this action.
* @return Returns true if the event was handled correctly,
otherwise false.
*/
 override fun launchApp(appParameter: String?): Boolean {
 return false
 }
 /**
* :: Opening of the "Feedback" page, which is taken over by the
host app.
* @return returns true if the host app takes over this event,
otherwise false and opens the default feedback page.
*/
 override fun feedback(bundle: Bundle): Boolean {
 return false
 }
 /**
* Get user avatar, return information via callback, pass through
to mini program by SDK
*/
 override fun chooseAvatar(callback: IAppletHandler.IAppletCallback)
{
 callback.onFailure()
 }
 /**
* Open a customer service session and have the host app implement
the specific operation
* @param json Data passed from the mini program to the host app
* @return Returns true if the session is successfully opened,
otherwise returns false
*/
 override fun contact(json: JSONObject): Boolean {
 return false
 }
 /**
* Get the registered "More" menu item
*
* @param appId mini program ID
* @return registered "More" menu item
*/
 fun getRegisteredMoreMenuItems(appId: String): List<MoreMenuItem>?
 /**
* The "More" menu item of the registration is clicked
*
* @param appId mini program ID
* @param path mini program page path
* @param menuItemId The ID of the clicked menu item
* @param appInfo mini program information, a string of json containing
information such as mini program id, mini program name, mini program icon, user id, and
the content of the data forwarded.
* The content of [appInfo] is in the following format.
* {
* "appTitle": "Vantaa mini program",
* "appAvatar":
"https:\/\/www.finogeeks.club\/statics\/images\/swan_mini\/swan_logo.pn
g",
* "appId": "5df36b3f687c5c00013e9fd1",
* "appType": "trial",
* "userId": "finogeeks",
* "cryptInfo":
"SFODj9IW1ENO8OA0El8P79aMuxB1DJvfKenZd7hrnemVCNcJ+Uj9PzkRkf/Pu5nMz0cGjj
0Ne4fcchBRCmJO+
As0XFqMrOclsqrXaogsaUPq2jJKCCao03vI8rkHilrWxSDdzopz1ifJCgFC9d6v29m9jU29
wTxlHsQUtKsk/wz0BROa+aDGWh0rKvUEPgo8mB+40/
zZFNsRZ0PjsQsi7GdLg8p4igKyRYtRgOxUq37wgDU4Ymn/yeXvOv7KrzUT",
* "params": {
* "title": "apt-test-tweet-Interface-test-released-dynamics! @#$
%......&*(",
* "desc": "Service Experts by Your Side",
* "imageUrl": "finfile:\/\/tmp_fc15edd8-2ff6-4c54-9ee9-
fe5ee034033d1576550313667.png",
* "path": "pages\/tweet\/tweet-detail.html?fcid=
%40staff_staff1%3A000000.finogeeks.com&timelineId=db0c2098-031e-41c4-
b9c6- 87a5bbcf681d&shareId=3dfa2f78-19fc-42fc-b3a9-4779a6dac654",
* "appInfo": {
* "weixin": {
* "path":"\/studio\/pages\/tweet\/tweet-detail",
* "query": {
* "fcid":"@staff_staff1:000000.finogeeks.com",
* "timelineId": "db0c2098-031e-41c4-b9c6-87a5bbcf681d"
* }
* }
* }
* }
* }
* Description of the fields in [appInfo].
* appId mini program ID
* appTitle mini program name
* appAvatar mini program avatar
* appType mini program type, where trial means experience, temporary
means temporary, review means review, release means online and
development means development
* userId User ID
* cryptInfo mini program encryption information
* other parameters attached to params, passed by the mini program itself
*
* @param bitmap The mini program cover image. If the
[appInfo].params.imageUrl field is a link address of http, https, then
the mini program cover image
* Just take the image corresponding to [appInfo].params.imageUrl,
otherwise the cover image of the mini program is taken as [bitmap].
*/
 fun onRegisteredMoreMenuItemClicked(appId: String, path: String,
menuItemId: String, appInfo: String?, bitmap: Bitmap?, callback:
IAppletCallback)
 /**
* Get the grey-scale release configuration parameters
*
* @param appId mini program ID
* @return grayscale release configuration parameters
*/
 fun getGrayAppletVersionConfigs(appId: String):
List<GrayAppletVersionConfig>?
 /**
* The "Close" button in the mini program navigation bar is clicked
*
* @param appId mini program ID
*/
 fun onNavigationBarCloseButtonClicked(appId: String)
}

API

kotlin
/**
* Set the [IAppletHandler] implementation class
*
* @param appletHandler [IAppletHandler] implementation class
*/
fun setAppletHandler(appletHandler: IAppletHandler)

Example of a call to ####

kotlin
FinAppClient.appletApiManager.setAppletHandler(
 object : IAppletHandler {
 override fun shareAppMessage(
 appInfo: String,
 bitmap: Bitmap?
 callback: IAppletHandler.
 ) {
 }
 })
java
FinAppClient. INSTANCE. getAppletApiManager(). setAppletHandler(new
IAppletHandler() {
 @Override
 public void shareAppMessage(@NotNull String appInfo,
 @Nullable Bitmap bitmap,
 @NotNull IAppletCallback callback) {
 }
});

Note

  • The FinAppClient class needs to be used in the mini program process.
  • For asynchronous callback methods (with callbacks as parameters), make sure that you use callbacks regardless of whether the business logic succeeds or not, otherwise the result of the call will not be received on the mini program side.

2. IAppletProcessHandler

API

kotlin
/**
* Set the implementation class of [IAppletProcessHandler].
*
* @param appletProcessHandler [IAppletProcessHandler] implementation
class
*/
fun setAppletProcessHandler(appletProcessHandler:
IAppletProcessHandler)

Example of a call to ####

kotlin
FinAppProcessClient.appletProcessApiManager.setAppletProcessHandler(
 object : IAppletProcessHandler {
 override fun onNavigationBarMoreButtonClicked(
 context: Context,
 appId: String
 ): Boolean {
 return true // return true means that the "more" button
click event is handled by itself, blocking the default menu display
logic.
 }
 })
java
FinAppProcessClient. INSTANCE. getAppletProcessApiManager().
setAppletProcessHandler(new IAppletProcessHandler(){
 @Override
 public boolean onNavigationBarMoreButtonClicked(@NonNull Context
context, @NonNull String appId) {
 return true; // return true means that the "more" button click
event is handled by itself, blocking the default menu display logic.
 }
});

Note

  • The FinAppProcessClient class needs to be used in the mini program process. Please use the FinAppClient.INSTANCE.isFinAppProcess() method to determine if you are in an mini program process
  • The IAppletProcessHandler interface method is executed in the mini program process.

3. IAppletLifecycleCallback

If an external party needs to listen to the lifecycle of the mini program, they can call the setAppletLifecycleCallback interface of the IAppletApiManager to pass the instance of IAppletLifecycleCallback to the SDK, and when the lifecycle of the mini program changes, the SDK will call back to the external party via the When the lifecycle of the mini program changes, the SDK will call back to the outside via the corresponding method ofIAppletLifecycleCallback `.

kotlin
/**
* :: mini program lifecycle callback interface
*/
interface IAppletLifecycleCallback {

 /**
* The current page state of the mini program, corresponding to
[Activity]. [onCreate] corresponds to
*/
 fun onCreate(appId: String)
 /**
* The current page state of the mini program, corresponding to
[Activity]. [onStart] corresponds to
*/
 fun onStart(appId: String)
 /**
* The current page state of the mini program, corresponding to
[Activity]. [onResume] corresponds to
*/
 fun onResume(appId: String)
 /**
* The current page state of the mini program, corresponding to
[Activity]. [onPause] corresponds to
*/
 fun onPause(appId: String)
 /**
* The current page state of the mini program, corresponding to
[Activity]. [onStop] corresponds to
*/
 fun onStop(appId: String)
 /**
* The current page state of the mini program, which corresponds to
[Activity]. [onDestroy] corresponds to
*/
 fun onDestroy(appId: String)
}

API

kotlin
/**
* Set [IAppletLifecycleCallback]
*
* @param appletLifecycleCallback [IAppletLifecycleCallback] object
*/
fun setAppletLifecycleCallback(appletLifecycleCallback:
IAppletLifecycleCallback)

Example of a call to ####

kotlin
FinAppClient.appletApiManager.setAppletLifecycleCallback(object :
IAppletLifecycleCallback {
override fun onCreate(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onCreate : $appId")
 }
 override fun onInitComplete(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onInitComplete : $appId")
 }
 override fun onStart(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onStart : $appId")
 }
 override fun onResume(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onResume : $appId")
 }
 override fun onPause(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onPause : $appId")
 }
 override fun onStop(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onStop : $appId")
 }
 override fun onDestroy(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onDestroy : $appId")
 }
 override fun onFailure(appId: String, errMsg: String) {
 Log.d(TAG, "IAppletLifecycleCallback onFailure : $appId ,
$errMsg")
 }
})
java
FinAppClient. INSTANCE. getAppletApiManager().
setAppletLifecycleCallback(new IAppletLifecycleCallback() {
 @Override
 public void onCreate(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onCreate : " + appId);
 }
 @Override
 public void onInitComplete(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onInitComplete : " +
appId);
 }
 @Override
 public void onStart(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onStart : " + appId);
 }
 @Override
 public void onResume(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onResume : " + appId);
 }
 @Override
 public void onPause(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onPause : " + appId);
 }
 @Override
 public void onStop(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onStop : " + appId);
 }
 @Override
 public void onDestroy(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onDestroy : " + appId);
 }
 @Override
 public void onFailure(@NotNull String appId, String errMsg) {
 Log. d(TAG, "IAppletLifecycleCallback onFailure : " + appId);
 }
});

4. IAppletOpenTypeHandler

Starting with 2.37.13, the IAppletHandler is split into interface classes dedicated to open-type type events, including getPhoneNumber, chooseAvatar, launchApp, contact, shareAppMessage, feedback.

Code example.

kotlin
FinAppClient.appletOpenTypeHandler = MyAppletOpenTypeHandler()
java
FinAppClient. INSTANCE. setAppletOpenTypeHandler(new MyAppletOpenTypeHandler());

Note

  • The FinAppClient class needs to be used in the applet process.
  • Setting up IAppletOpenTypeHandler will override the implementation of the open-type method above in IAppletHandler.
  • If the WeChat Extension SDK (WeChatSDK) is integrated, do not use this interface class, but instead use.
kotlin
WeChatOpenTypeClient.instance.iWeChatOpenTypeHandler =
MyWeChatAppletOpenTypeHandler()