Usage

The SDK for the mini-app provides several methods for interacting with the mini-program. Before getting started, please apply for access to the mini-program functionality on the mini-program open platform and register your mini-app. Here are some common usage examples:

Set Theme Style

miniAppService?.setThemeStyle(isDark = true)

Set Language

miniAppService?.setLanguage("zh-CN")

Launch Params

WebAppLaunchWithDialogParameters.Builder()
            .owner(lifecycleOwner)
            .context(context)
            .url(url)
            .isLaunchUrl(false)
            .isLocal(false)
            .autoExpand(true)
            .startParam("Your mini-app startParams")
            .useCache(true) 
            .useModalStyle(false)
            .useCustomNavigation(false)
            .onDismissListener {}
            .build()
  • owner(lifecycleOwner): Specifies the lifecycle owner associated with the dialog launching the web app.
  • context(context): Sets the context in which the web app is launched.
  • url(url): Defines the URL of the web app to be launched.
  • isLaunchUrl(false): Indicates whether the URL should be launched.
  • isLocal(false): Specifies if the web app is local or not.
  • autoExpand(true): Determines if the web app should automatically expand.
  • startParam("Your mini-app startParams"): Sets the start parameters for the mini-app.
  • useCache(true): Specifies whether caching should be used.
  • useModalStyle(false): Page style setting, default is full-screen mode.
  • useCustomNavigation(false): Toolbar style setting, default style and custom style.
  • onDismissListener {}: Sets a listener for when the dialog is dismissed.

Preload Mini App with botName and miniAppName

val config = WebAppPreloadParameters.Builder()
            .owner(lifecycleOwner)
            .context(context)
            .botName("MatrixBot102")
            .miniAppName("cybercat")
            .build()        

miniAppService?.preload(config)

Preload Mini App with URL

val config = WebAppPreloadParameters.Builder()
            .owner(lifecycleOwner)
            .context(context)
            .url("https://mini-app-me-host/botName/miniAppName")
            .build()        

miniAppService?.preload(config)

Launch Mini App with botName and miniAppName

val config = WebAppLaunchWithDialogParameters.Builder()
            .owner(lifecycleOwner)
            .context(context)
            .botName("MatrixBot102")
            .miniAppName("cybercat")
            .onDismissListener(onDismissListener)
            .build()        

miniAppService?.launch(config)

Launch Mini App with URL

val config = WebAppLaunchWithDialogParameters.Builder()
            .owner(lifecycleOwner)
            .context(context)
            .url("https://mini-app-me-host/botName/miniAppName")
            .onDismissListener(onDismissListener)
            .build() 

miniAppService?.launch(config)

Embed Mini App with botName and miniAppName into a Container

val config = WebAppLaunchWithParentParameters.Builder()
            .owner(lifecycleOwner)
            .context(context)
            .botName("MatrixBot102")
            .miniAppName("cybercat")
            .onDismissListener(onDismissListener)
            .parentView(parentView)
            .layoutParams(layoutParams)
            .build()  

miniAppService?.launch(config)

Embed Mini App with URL into a Container

val config = WebAppLaunchWithParentParameters.Builder()
            .owner(lifecycleOwner)
            .context(context)
            .url("https://mini-app-me-host/botName/miniAppName")
            .onDismissListener(onDismissListener)
            .parentView(parentView)
            .layoutParams(layoutParams)
            .build()  

miniAppService?.launch(config)