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
@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("customAsyncEvent")public void custom(final RequestEvent req) {// Get the parameters// req.jsonParams// Get current mini program information// mMiniAppContext.getMiniAppInfo();// 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);}@JsEvent("customSyncEvent")public String custom1(final RequestEvent req) {// Get the parameters// req.jsonParams// Get current mini program information// mMiniAppContext.getMiniAppInfo();// Return the data synchronouslyJSONObject jsonObject = new JSONObject();try {jsonObject.put("key", "value");} catch (JSONException e) {throw new RuntimeException(e);}return req.okSync(jsonObject);}/*** Example of overriding the built-in API (getAppBaseInfo is the SDK’s built-in API)* @param req*/@JsEvent("getAppBaseInfo")public void getAppBaseInfo(final RequestEvent req) {// Get the parameters// req.jsonParams// Get current mini program information// mMiniAppContext.getMiniAppInfo();// 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);}@JsEvent("testState")public void testState(final RequestEvent req) {try {// Callback intermediate statesreq.sendState(req, new JSONObject().put("progress", 1));req.sendState(req, new JSONObject().put("progress", 30));req.sendState(req, new JSONObject().put("progress", 60));req.sendState(req, new JSONObject().put("progress", 100));} catch (JSONException e) {e.printStackTrace();}JSONObject jsonObject = new JSONObject();try {jsonObject.put("key", "test");req.ok(jsonObject);} catch (JSONException e) {throw new RuntimeException(e);}}}
// Asynchronous API callvar opts = {api_name: 'customAsyncEvent',progress: function(res) {// Code to listen for sendState status updates},success: function(res) {},fail: function(res) {},complete: function(res) {},data: { // Input parametersname : 'kka',age : 22}}wx.invokeNativePlugin(opts);// Synchronous API callvar opts = {api_name: 'customSyncEvent',sync:true}var rst = wx.invokeNativePlugin(opts);
@JsEvent.{"extApi": [{"name": "customSyncEvent","sync": true,"params": {"name": "","age": 0,"object": {"key": ""}}},{"name": "customAsyncEvent2","sync": false,"params": {"name": "","age": ""}}],"overwriteWxApi": false}

@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;}
{"extApi": [{"name": "customSyncEvent","sync": true,"params": {"name": "","age": ""}},{"name": "customAsyncEvent","sync": false,"params": {"name": "","age": ""}},{"name": "getAppBaseInfo","sync": false,"params": {}}],"overwriteWxApi": true}
var opts = {progress: function(res) {},success: function(res) {},fail: function(res) {},complete: function(res) {}}wx.testState(opts);wx.customAsyncEvent({"name":"123","age":"18"})wx.getAppBaseInfo() // This will override the system API and call the custom API.
@JsPlugin(secondary = true)public class CustomPlugin extends BaseJsPlugin {@JsEvent("testStartActivityForResult")public void testStartActivityForResult(final RequestEvent req) {Activity activity = req.activityRef.get();TmfMiniSDK.addActivityResultListener(new IActivityResultListener() {@Overridepublic boolean doOnActivityResult(int requestCode, int resultCode, Intent data) {TmfMiniSDK.removeActivityResultListener(this);Log.i(ModuleApplet.TAG, data.getStringExtra("key"));req.ok();return true;}});}}
@JsPlugin(secondary = true)public class CustomPlugin extends BaseJsPlugin {@JsEvent("testStartActivityForResult")public void testStartActivityForResult(final RequestEvent req) {Activity activity = req.activityRef.get();TmfMiniSDK.addActivityResultListener(new IActivityResultListener() {@Overridepublic boolean doOnActivityResult(int requestCode, int resultCode, Intent data) {TmfMiniSDK.removeActivityResultListener(this);Log.i(ModuleApplet.TAG, data.getStringExtra("key"));req.ok();return true;}});// Note: requestCode must be >=1000000, otherwise it may conflict with the internal requestCode, causing unknown issues.activity.startActivityForResult(new Intent(activity, TransActivity.class), 1000000);}}
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