All Products
Document Center

Send custom event to the mini program

Last Updated: Jun 09, 2021

The function of sending custom event to mini program through Android custom View is only supported in mPaaS and later. When the current baseline version is lower than, refer to mPaaS Upgrade Guide to upgrade the version to

Add custom event callback in the tag of mini program

Add custom event callback in xxx.axml.

  1. <mpaas-component
  2. id="mpaas-map"
  3. type="custom_map"
  4. style="{{ width: 200, height: 200 }}"
  5. color="#FFFF00FF"
  6. onAnimationStart="onAnimationStart"
  7. />

onAnimationStart is a custom callback event, and the name of the custom event should start with on.

Handle custom events in JavaScript

  1. onAnimationStart(data) {
  2. my.showToast({
  3. type: 'success',
  4. content: `onAnimationStart: ${JSON.stringify(data)}`,
  5. });
  6. },

Trigger client custom View event

  1. JSONObject data = new JSONObject();
  2. data.put("sth", "start");
  3. mMPBaseEmbedView.sendEventToTiny("onAnimationStart", data);

mMPBaseEmbedView is an instance of the class. The first parameter in the sendEventToTiny is the name of event callback, which needs to be consistent with the mini program; the second parameter is the event parameter.