Quick Start

Last Updated on : 2025-12-30 08:17:26download

This topic describes how to quickly get started using the MiniApp SDK with a HarmonyOS project.

Initialize the SDK

SDK initialization code is located in entry/src/main/ets/app/AppAbilityStage.ets. Initialization is automatically completed when the app starts. For a complete initialization code example, refer to the entry/src/main/ets/app/AppAbilityStage.ets file in the sample project.

Open miniapp

The APIs used to manage a miniapp include but are not limited to the following:

  • Open a miniapp
  • Open a device panel

Dedicated APIs are provided to open a miniapp in different scenarios. The HarmonyOS version uses ThingRouter to open miniapp and panel.

Before opening a miniapp, you need to import the @thingsmart/godzillapage component in entry/thing-biz-components.json first.

Open miniapp

Use ThingRouter to open a miniapp:

import { ThingRouter } from "@thingsmart/thingrouter";

// Open miniapp
ThingRouter.getInstance()
  .setParam({
    // Miniapp URL, format: godzilla://miniprogramId/pagePath?queryA=a
    'url': 'godzilla://miniprogramId/pagePath'  
  })
  .push("miniApp")

Open device panel

Use ThingRouter to open a device panel:

import { ThingRouter } from "@thingsmart/thingrouter";

// Open device panel
ThingRouter.getInstance()
  .setParam({
    'devId': 'deviceId',  // Device ID
    'groupId': 'groupId',  // Device group ID (optional)
    /**
     * Passed through to initialProps and contextProps
     */
    // 'propsData': {} as Record<string, Object>  // Custom parameters (optional)
  })
  .push("panel")

Supported parameters

The miniapp initialization supports multiple parameter formats. The following table lists all supported parameters:

Parameter Name Parameter Type Required Description Use Case
url string Yes (Method 1) Miniapp URL, format: godzilla://miniprogramId/pagePath?queryA=a Open miniapp by URL
miniAppId string Yes (Method 2) Miniapp ID, available on the Tuya Developer Platform Open miniapp by miniapp ID
path string No Miniapp page path Used with miniAppId
uniqueCode string Yes (Method 3) Unique code, obtained by scanning QR code or other methods Open miniapp by unique code
devId string Yes (panel) Device ID Open device panel
groupId string No Device group ID Open device panel
propsData Record<string, Object> No Custom parameters, passed through to initialProps and contextProps Open device panel
initialProps Record<string, Object> No Initial properties, passed through to miniapp’s initialProps Open miniapp
contextProps Record<string, Object> No Context properties, passed through to miniapp’s contextProps Open miniapp
customMiniAppType MiniAppType No Custom miniapp type Open miniapp
extraData Record<string, Object> No Additional business data Open miniapp
position string No Location information Open miniapp
entryCode string No Miniapp entry code Open miniapp

Query related information

During miniapp runtime, some basic information is required to help Tuya better locate issues. Therefore, Tuya provides APIs to query some runtime information.

First, you need to get the MiniAppContainerInfoService service instance:

import { MiniAppContainerInfoService } from "@thingsmart/godzillainterface";
import { ThingRouter } from "@thingsmart/thingrouter";

// Get miniapp container information service
const miniappService = await ThingRouter.getServiceMgr()
  .getServiceAsync<MiniAppContainerInfoService>('MiniAppContainerInfoService');

API description

/**
 * Returns the latest base library version
 */
abstract jsSdkVersion(): string;

/**
 * Returns the miniapp container version corresponding to the current SDK
 */
abstract containerVersion(): string;

/**
 * Returns the TTT-Kits version information that the current App depends on
 */
abstract tttKitsInfo(): Record<string, string>;

/**
 * Returns the list of recently opened miniapps
 */
abstract recentlyOpenedMiniPrograms(): RecentlyOpenedMiniProgram[];

/**
 * Actively clears miniapp cache
 */
abstract cleanCache(): void;