Announcement: Tencent Cloud Mini Program Platform Renamed to Tencent Cloud Super App as a Service on January 2, 2025
Console Updates
Android SDK Updates
iOS SDK Updates
Flutter SDK Updates
IDE Updates
Base Library Updates
@ProxyService(proxy = MiniConfigProxy.class)
@ProxyService(proxy = MiniConfigProxy.class)public class MiniConfigProxyImpl extends MiniConfigProxy {/*** Obtains the Application instance of the superapp* Note: 1. The mini program adopts a multi-process architecture. Ensure that sub-processes can also properly access the Application instance.* 2. It is recommended to cache the Application instance in Application.attachBaseContext* to prevent the SDK from obtaining a null Application instance due to component timing issues.* @return*/@Overridepublic Application getApp() {// Must use the Application instance of the superappreturn "your superapp Application";}/*** Creates initialization configuration information* @return*/@Overridepublic MiniInitConfig buildConfig() {MiniInitConfig.Builder builder = new MiniInitConfig.Builder();MiniInitConfig config = builder.configAssetName("tcsas-android-configurations.json") // Configuration file name in assets.autoRequestPermission(true) // Whether to automatically request system permissions for APIs that require permissions.debug(true) // Log switch, default is off.build();return config;}}
/*** Whether to force update when opening the mini program (effective for cold startup). false: Prioritizes using local cache while asynchronously fetching the latest data. true: Opens the mini program only after receiving a network response.*/public boolean isForceUpdate = false;/*** Entry address, supports adding parameters: path?key=value&key1=value1*/public String entryPath;/*** Receives error messages during the mini program launch process*/public ResultReceiver resultReceiver;/*** Mini program launch parameters*/public String params;/*** Sets the task mode to be used when opening the mini program** false: Multi-task mode; true: Single-task mode*/public boolean isSingleTask;
// Open a mini program using the mini program appid//TmfMiniSDK.startMiniApp(activity, appId, new MiniStartOptions());
TmfMiniSDK.startMiniApp(activity, appId, miniStartOptions);
TmfMiniSDK.startMiniAppByScan(activity);
<string name="mini_sdk_intent_filter_scheme">your scheme</string>
Parameter | Type | Required | Description |
appId | String | true | Mini program appid |
path | String | false | Mini program entry path, which requires URL encoding. |
param | String | false | The query passed to the mini program, which requires URL encoding. |


/*** Mini program search** @param searchOptions* @param callback*/public static void searchMiniApp(SearchOptions searchOptions, MiniCallback<List<MiniApp>> callback)
/*** Gets the list of recently accessed mini programs* @param callback*/public static void getRecentList(IRecentMiniCallback callback)
// Implement the MiniAppProxy APIpublic class YourMiniAppProxyImpl extends BaseMiniAppProxyImpl {@Overridepublic Locale getLocale() {// Return the language you want to setreturn Locale.SIMPLIFIED_CHINESE; // Simplified Chinese// or return Locale.US; // English// or return new Locale("ar", "SA"); // Arabic// or return new Locale("in", "ID"); // Indonesian// or return Locale.FRANCE; // French}}
/*** User account, must be unique. After setting, data will be stored in isolation based on the account. Typically, use uin or openid*/@Overridepublic String getAccount() {return "tmf_test";}
TmfMiniSDK.stopAllMiniApp(MainActivity.this);

The return value of the onCapsuleButtonCloseClick method indicates whether a custom close button listener is implemented. A return value of true indicates customization, while false (the default value) indicates the use of the default listener./*** Tap event for the capsule button's close option* Called in the subprocess.** @param miniAppContext Mini program runtime environment (mini program process, not main process)* @param onCloseClickedListener Callback when the mini program is closed* @return - Returns false if this API is not supported*/public abstract boolean onCapsuleButtonCloseClick(IMiniAppContext miniAppContext,DialogInterface.OnClickListener onCloseClickedListener);

/*** Tap event for the More options on the capsule button** @param miniAppContext Mini program runtime environment* @return - Returns false if this API is not supported*/public abstract boolean onCapsuleButtonMoreClick(IMiniAppContext miniAppContext);

/*** Returns the buttons for the capsule's More panel. The IDs for extension buttons must be set within the range of [100, 200]; otherwise, the addition will be invalid.* Calling environment: Subprocess** @param builder* @return*/public abstract ArrayList<MoreItem> getMoreItems(MoreItemList.Builder builder);
@Overridepublic ArrayList<MoreItem> getMoreItems(IMiniAppContext miniAppContext, MoreItemList.Builder builder) {MoreItem item1 = new MoreItem();// Set the menu ID (required), the ID for extension buttons must be within the range of [100, 200]; otherwise, the addition will be invalid.item1.id = ShareProxyImpl.OTHER_MORE_ITEM_1;// Set the menu title (optional)item1.text = getString(miniAppContext, R.string.applet_mini_proxy_impl_other1);// Set the menu icon (optional)item1.drawable = R.mipmap.mini_demo_about;// Set the visual accessibility description (optional). Defaults to the menu title.item2.contentDescription = "Visual accessibility description for the menu";// Listen for tap eventsitem2.onClickListener = new MoreItem.MoreItemClickListener() {@Overridepublic void onClick(IMiniAppContext context, MoreItem item) {// Handle tap event}};// Adjust the order as neededbuilder.addMoreItem(item1)// Add built-in menu items as needed.addRestart(getString(miniAppContext, R.string.applet_mini_proxy_impl_restart),R.mipmap.mini_demo_restart_miniapp)// Add built-in menu items as needed.addAbout(getString(miniAppContext, R.string.applet_mini_proxy_impl_about),R.mipmap.mini_demo_about)// Add built-in menu items as needed.addSetting(getString(miniAppContext, R.string.mini_sdk_more_item_setting_0),R.drawable.mini_sdk_setting,// Set the visual accessibility description (optional). Defaults to the menu title."Mini program settings");return builder.build();}private String getString(IMiniAppContext miniAppContext, int id) {return miniAppContext.getContext().getString(id);}
Mini program API | AbsMiniUiProxy method |
wx.showLoading |
|
wx.showToast |
|
wx.showActionSheet |
|
public abstract class LogProxy {/*** Log printing*@param logLevel Log print level* @param tag log tag* @param msg Print message* @param t Exception*/abstract public void log(int logLevel, String tag, String msg, Throwable t);/*** Whether to use colored output, used to control log display.*/abstract public boolean isColorLevel();}
public interface IDarkModeProxy {boolean isDarkMode();}
@JsPlugin(secondary = true).@JsEvent("event name") on the method. When the mini program's JavaScript calls "event name," the corresponding method marked with @JsEvent will be called.@JsEvent supports defining multiple event names.@JsPlugin(secondary = true)public class CustomPlugin extends BaseJsPlugin {@JsEvent("testSync")public String custom1(final RequestEvent req) {// Get the parameters//req.jsonParams// Return the data synchronouslyJSONObject jsonObject = new JSONObject();try {jsonObject.put("key", "value");} catch (JSONException e) {throw new RuntimeException(e);}return req.okSync(jsonObject);}@JsEvent("testAsync")public void getAppBaseInfo(final RequestEvent req) {// Get the parameters//req.jsonParams// Return the data asynchronously//req.fail();//req.ok();JSONObject jsonObject = new JSONObject();try {jsonObject.put("key", "test");} catch (JSONException e) {e.printStackTrace();}req.ok(jsonObject);}}
// Asynchronous API callvar opts = {api_name: 'testAsync',success: function(res) {},fail: function(res) {},complete: function(res) {},data: { // Input parametersname: 'kka',Age 22}}wx.invokeNativePlugin(opts);// Synchronous API callvar opts = {api_name: 'testSync',sync:true}var rst = wx.invokeNativePlugin(opts);
{"extApi":[{"name": "test","sync": false,"params": {"data": ""}},{"name": "testSync","sync": true,"params": {"name": "","title": ""}}]}

@ProxyService(proxy = MiniAppProxy.class)public class MiniAppProxyImpl extends BaseMiniAppProxyImpl {@Overridepublic MiniConfigData configData(Context context, int configType, JSONObject params) {if(configType == MiniConfigData.TYPE_CUSTOM_JSAPI) {// Custom JSAPI configurationMiniConfigData.CustomJsApiConfig customJsApiConfig = new MiniConfigData.CustomJsApiConfig();customJsApiConfig.jsApiConfigPath = "tcmpp/custom-config.json";return new MiniConfigData.Builder().customJsApiConfig(customJsApiConfig).build();}return null;}
// Asynchronous API callvar opts = {success: function(res) {},fail: function(res) {},complete: function(res) {},data: {name : 'kka',age : 22}}wx.testAsync(opts);// Synchronous API callvar rst = testSync(opts);
@ProxyService(proxy = ExternalElementProxy.class)public class MyExternalElementProxy extends ExternalElementProxy{}
/*** Creates a component. This API is called when the mini program creates a custom native component.** @param widgetId Unique ID of the component created by the mini program* @param widgetContext Context of the mini program component, used for callbacks to the mini program* @param type Type name of the component created by the mini program* @param parent Parent container that holds the native component* @param params Parameters passed when the mini program creates the component*/public abstract void handleInsertElement(long widgetId, ExternalWidgetContext widgetContext,String type, ViewGroup parent, JSONObject params);
/*** Updates component style. This API is called when the mini program updates the style of a custom native component.** @param widgetId Mini program component ID* @param widgetContext Context of the mini program component, used for callbacks to the mini program* @param params Parameters passed when the mini program creates the component*/public abstract void handleUpdateElement(long widgetId, ExternalWidgetContext widgetContext,JSONObject params);
/*** Operates a component. This API is called when the mini program needs to send commands or call special methods on the component.** @param widgetId Mini program component ID* @param widgetContext Context of the mini program component, used for callbacks to the mini program* @param params Parameters passed when the mini program creates the component*/public abstract void handleOperateElement(long widgetId, ExternalWidgetContext widgetContext,JSONObject params);
/*** Deletes a component** @param widgetId Mini program component ID* @param widgetContext Context of the mini program component, used for callbacks to the mini program*/public abstract void handleRemoveElement(long widgetId, ExternalWidgetContext widgetContext);
/*** Sends the onExternalElementEvent event to the mini program** @param jsonObject JSON data carried with the event*/public final void onExternalElementEvent(JSONObject jsonObject);/*** Calls the success callback method provided by the mini program** @param jsonObject JSON data for the callback, can be null*/public final void callbackSuccess(JSONObject jsonObject);/*** Calls the fail callback method provided by the mini program** @param jsonObject JSON data for the callback, can be null/// @param message Error message*/public final void callbackFail(JSONObject jsonObject, String message);
<external-elementid="comp1"type="maTestView"_insert2WebLayer="true"style="width: 200px;height: 100px;"bindexternalelementevent="handleEvent"></external-element>
_insert2WebLayer indicates whether the component is a same-layer component or a non-same-layer component (true for same-layer, which requires the client to implement a same-layer component proxy; false for non-same-layer, which requires the client to implement a non-same-layer proxy). The bindexternalelementevent can capture events passed from the native side, such as onExternalElementEvent or onXWebExternalElementEvent. The callback parameters include:{target,currentTarget,timeStamp,touches,detail, // parameters passed from native}
this.ctx = wx.createExternalElementContext('comp1');
this.ctx.call({params1: {name: 'name1',age: 11},params2: {name: 'name2',age: 22},success: (e) => {console.log('====operate success=====', e)},fail: (e) => {console.log('====operate fail=====', e)},complete: (e) => {console.log('====operate complete=====', e)}})
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback