# Others
# 1. Set Mini-Program Activity Transition Animation
Supported App Types
Mini-Program✅ Mini-Game✅ H5 Application✅
# API
/**
* Set the Mini-Program Activity transition animation
*
* @param anim [Anim] animation
*/
fun setActivityTransitionAnim(anim: Anim)
# Usage Example
# 2. Native Sends Event to Mini-Program
Supported App Types
Mini-Program✅ Mini-Game✅ H5 Application✅
# API
/**
* Native sends an event to the Mini-Program
* @param appId
* @param params Event parameters
*/
fun sendCustomEvent(appId: String, params: String)
# Usage Example
# 3. Create a [FinAppletWebView] Instance
This method has been deprecated since version
2.12.4. If you need to useFinAppletWebView, instantiate the class directly.
# API
/**
* Create a [FinAppletWebView] instance
*
* @param context [Context] object
* @return A [FinAppletWebView] instance
*/
fun createFinAppletWebView(context: Context): FinAppletWebView
# Usage Example
# 4. Cross-Process API Calls
# 4.1 Main Process Calls Mini-Program Process
Supported App Types
Mini-Program✅ Mini-Game✅ H5 Application✅
Call Must be called in the main process
FinAppClient.appletApiManager.callInAppletProcess(
FinAppClient.appletApiManager.getCurrentAppletId().orEmpty(),
"Main process calls Mini-Program process method name",
"Main process calls Mini-Program process parameters",
object : FinCallback<String> {
override fun onSuccess(result: String?) {
toast("Result returned from Mini-Program process:$result")
}
override fun onError(code: Int, error: String?) {
}
override fun onProgress(status: Int, info: String?) {
}
})
Receive Must register a handler method in the Mini-Program process. Use FinAppClient.isFinAppProcess(context) to determine if it's the Mini-Program process.
if (FinAppClient.isFinAppProcess(this)) {
FinAppProcessClient.appletProcessApiManager.setMainProcessCallHandler(
object : IAppletProcessApiManager.MainProcessCallHandler {
override fun onMainProcessCall(
name: String,
params: String?,
callback: IApiCallback?
) {
toast("Main process calls Mini-Program process:name:$name,params:$params")
callback?.onSuccess("Return result to main process")
}
})
}
# 4.2 Mini-Program Process Calls Main Process
Supported App Types
Mini-Program✅ Mini-Game✅ H5 Application✅
Call Must be called in the Mini-Program process
FinAppProcessClient.appletProcessApiManager.callInMainProcess(
"Mini-Program process calls main process method name",
"Mini-Program process calls main process parameters",
object : FinCallback<String> {
override fun onSuccess(result: String?) {
toast("Mini-Program process calls main process successfully:$result")
}
override fun onError(code: Int, error: String?) {
}
override fun onProgress(status: Int, info: String?) {
}
})
Receive Must register a handler method in the main process
FinAppClient.appletApiManager.setAppletProcessCallHandler(
object : IAppletApiManager.AppletProcessCallHandler {
override fun onAppletProcessCall(
name: String,
params: String?,
callback: IApiCallback?
) {
application.toast("Mini-Program process calls main process:name:$name,params:$params")
callback?.onSuccess("Return result to Mini-Program process")
}
})
# 5. Calling APIs in the Mini-Program Process
FinAppClient.appletApiManager can only be used in the main process.
In the Mini-Program process, use the methods in FinAppProcessClient.appletProcessApiManager.
For example:
FinAppProcessClient.appletProcessApiManager.getCurrentAppletId()
FinAppProcessClient.appletProcessApiManager.getAppletInfo()
FinAppProcessClient.appletProcessApiManager.sendCustomEvent(params)
# 6. Handling Events in the More Panel
Supported App Types
Mini-Program✅ Mini-Game✅ H5 Application✅
When customizing the Mini-Program More Panel, although the UI is self-designed, some functions can still reuse those in the SDK, such as the About page, Settings page, Feedback, Forwarding, etc. You can call the APIs under MoreMenuHelper in the button click event to implement navigation and corresponding logic.
# 6.1 Navigate to the Mini-Program About Page
fun goToAboutPage(context: Context)
Example code:
MoreMenuHelper.goToAboutPage(context)
# 6.2 Trigger Forwarding Event
/**
* Trigger the forwarding action, consistent with the "Forward" behavior of the SDK's default menu. The forwarding logic needs to be handled in the delegate method shareAppMessage().
*/
fun invokeForwardMenuAction(context: Context)
Example code:
MoreMenuHelper.invokeForwardMenuAction(context)
# 6.3 Navigate to the Feedback Page
fun goToFeedbackPage(context: Context)
Example code:
MoreMenuHelper.goToFeedbackPage(context)
# 6.4 Navigate to the Settings Page
fun goToSettingPage(context: Context)
Example code:
MoreMenuHelper.goToSettingPage(context)
# 6.5 Get the Mini-Program's Debug Mode
fun isEnableAppletDebug(context: Context): Boolean
Example code:
MoreMenuHelper.isEnableAppletDebug(context)
# 6.6 Set the Mini-Program's Debug Mode
/**
* Enable/disable the Mini-Program's debug mode. If config.enableAppletDebug is set to true, enabling/disabling the debug mode operation will be invalid.
* @param enableAppletDebug true: enable, false: disable
*/
fun setEnableAppletDebug(context: Context, enableAppletDebug: Boolean)
Example code:
MoreMenuHelper.setEnableAppletDebug(context, true)
# 6.7 Get the Mini-Program's Favorite Status
/**
* Get the current Mini-Program's favorite status
*
* @return Returns null if the status cannot be obtained
*/
fun isAppletFavorite(context: Context): Boolean?
Example code:
MoreMenuHelper.isAppletFavorite(context)
# 6.8 Update the Mini-Program's Favorite Status
/**
* Update the Mini-Program's favorite status
*
* @param favorite true: favorite, false: unfavorite
*/
fun updateAppletFavoriteState(
context: Context,
favorite: Boolean,
callback: FinCallback<Any?>
)
Example code:
MoreMenuHelper.updateAppletFavoriteState(this, true, object : FinCallback<Any?> {
override fun onSuccess(result: Any?) {
}
override fun onError(code: Int, error: String?) {
}
override fun onProgress(status: Int, info: String?) {
}
})
# 6.9 Check if the Mini-Program Implements Custom Menu Functionality
Since some custom menus require data returned by the Mini-Program, the functionality is similar to the implementation of onShareAppMessage. You can call the following method to check if the current Mini-Program page has implemented the on{menuId}ButtonHandler method.
/**
* Check if the Mini-Program implements custom menu functionality
* The onShareAppMessage event is affected by whether the Mini-Program has called the showShareMenu/hideShareMenu API.
* If the Mini-Program calls showShareMenu and then this method is called for detection, the value corresponding to this event is true, regardless of whether the Mini-Program implements the onShareAppMessage event.
* If the Mini-Program calls hideShareMenu and then this method is called for detection, the value corresponding to this event is false, regardless of whether the Mini-Program implements the onShareAppMessage event.
*
* @param callback result JSONArray elements are {"eventName":"Mini-Program event name","menuId":"menu id","value":"whether the event is implemented"}
*/
fun checkMenus(
context: Context,
menuIds: List<String>,
callback: (result: JSONArray) -> Unit
)
Example code:
val menuIds = mutableListOf<String>()
menuIds.add("WXShareAPPFriends") // Menu configuration information is provided in the Mini-Program's onShareAppMessage method
menuIds.add("WXShareAPPMoments") // Menu configuration information is provided in the Mini-Program's onShareAppMessage method
menuIds.add("customMenu"); // Menu configuration information is provided in the Mini-Program's onCustomMenuButtonHandler method
MoreMenuHelper.checkMenus(context, menuIds) { result ->
}
# 6.10 Get Custom Menu Item Data
For custom menu items that require data returned by the Mini-Program, you can call this method to obtain the Mini-Program information returned by the corresponding Mini-Program page's on{menuId}ButtonHandler method.
/**
* Get menu data of type [MoreMenuType.ON_MINI_PROGRAM]
*
* @param callback Parameter field descriptions please refer to the delegate method onRegisteredMoreMenuItemClicked()
*/
fun getMiniProgramTypeMenuData(
context: Context,
menuId: String?,
callback: (appId: String, path: String, menuItemId: String, appInfo: String?, bitmap: Bitmap?) -> Unit
)
Example code:
getMiniProgramTypeMenuData(context, "customMenu") {
appId: String, path: String, menuItemId: String, appInfo: String?, bitmap: Bitmap? ->
}
# 6.11 Show/Hide More Menu List (Without clicking the More menu button in the Capsule Button)
/**
* Show/Hide the More menu list
* (For external SDK use)
*/
@JvmStatic
fun changeMoreMenuVisibility(context: Context) {
(context as? FinAppHomeActivity)?.run {
CapsuleHandler.MoreButtonClickHandler(appHost).changeDefaultMoreMenuVisibility()
}
}
Example code
MoreMenuHelper.changeMoreMenuVisibility(context)
# 7. Generate Token
Utility method, no need to distinguish between Mini-Program, Mini-Game, H5 Application.
/**
* Generate a token.
* Uses the original string, adds special characters, and generates a token using national cryptography.
* @param originText Original string
* @return Generated token
*/
fun generateTokenWithOriginText(originText: String): String
Example code:
val token = FinAppClient.appletApiManager.generateTokenWithOriginText("6007a0a122bad000012813eb");
# 8. Decrypt Token
Utility method, no need to distinguish between Mini-Program, Mini-Game, H5 Application.
/**
* Decrypt the token to obtain the original string within the token
* @param token Token generated using generateTokenWithOriginText
* @return Returns the original string
*/
fun originTextWithToken(token: String): String
Example code:
val originText = FinAppClient.appletApiManager.originTextWithToken(token);
# 9. Report Custom Event API
Utility method, no need to distinguish between Mini-Program, Mini-Game, H5 Application.
/**
* @param appletId Mini-Program ID
* @param eventId Event ID
* @param data Event data
* @return Whether successful
*/
fun reportEvent(appletId:String, eventId:String, data:JSONObject):Boolean
Example code:
val data = JSONObject()
data.put("test1", "xxx")
data.put("test2", "yyy")
FinAppClient.appletToolManager.reportEvent("Mini-Program ID for which the event needs to be reported", "Event ID to report", data)
# 10. Host-App Outputs Logs to Mini-Program's vConsole
Utility method, no need to distinguish between Mini-Program, Mini-Game, H5 Application.
/**
* Output logs to the Mini-Program's vConsole
* @param logMsg Log content
* @param logLevel Log level
* @param appletId Mini-Program ID
* @param callback Callback
*/
fun addConsoleLog(logMsg:String,logLevel:LogLevel,appletId:String,callback: FinSimpleCallback<String>? = null)
Example code:
FinAppClient.appletToolManager.addConsoleLog("xxxxx The log content you need to print", IAppletToolManager.LogLevel.WARN, "The Mini-Program ID of the Mini-Program whose vConsole the log should be output to")
# 11. Control the Display and Hiding of the Red Dot on the More Button
Utility method, no need to distinguish between Mini-Program, Mini-Game, H5 Application.
/**
* Control the display and hiding of the red dot on the More button
* @param appId Mini-Program ID. If not passed, defaults to the current Mini-Program.
* @param visible Whether to show the red dot true: show red dot false: hide red dot
*/
fun changMoreMenuRedDotVisibility(appId: String?, visible: Boolean)
Example code:
// Call in main process
FinAppClient.appletApiManager.changMoreMenuRedDotVisibility("appId",true)
// Call in Mini-Program process
FinAppProcessClient.appletProcessApiManager.changMoreMenuRedDotVisibility("appId",true)
# 12. Get Current Mini-Program Page Path
/**
* Get the current Mini-Program page path
* Example: page/index (without suffix and parameters)
*/
fun getCurrentPagePath(callback: FinSimpleCallback<String>)
Example code:
// Call in main process
FinAppClient.appletApiManager.getCurrentPagePath(object : FinSimpleCallback<String>() {
override fun onSuccess(result: String) {
super.onSuccess(result)
// result is the current page path
Toast.makeText(this@OpenAppletActivity, "getCurrentPagePath onSuccess : $result", Toast.LENGTH_SHORT).show()
}
override fun onError(code: Int, error: String?) {
super.onError(code, error)
}
})
# 13. Temporarily Control the Display/Hiding of the More Button on the Current Page (This setting becomes invalid when exiting the current page)
/**
* Temporarily control the display/hiding of the More button on the current page (This setting becomes invalid when exiting the current page)
*/
fun setCurrentPageCapsuleMoreMenuBtnHidden(hidden: Boolean)
Example code:
// Call in main process
FinAppClient.appletApiManager.setCurrentPageCapsuleMoreMenuBtnHidden(true)
# 14. Temporarily Control the Display/Hiding of the Close Button on the Current Page (This setting becomes invalid when exiting the current page)
/**
* Temporarily control the display/hiding of the Close button on the current page (This setting becomes invalid when exiting the current page)
*/
fun setCurrentPageCapsuleCloseBtnHidden(hidden: Boolean)
Example code:
// Call in main process
FinAppClient.appletApiManager.setCurrentPageCapsuleCloseBtnHidden(true)