this.context = my.createMpaasCustomComponentContext('mpaas-map');
'mpaas-map'
为小程序标签中 id 对应的 value,这里请填入您的 id。
this.context.postMessage({
actionType: 'setColor',
data: {
"color": "#FF00FF00"
}
});
其中 actionType
为客户端接收到的消息事件名称,data
为扩展参数。
public class MyTestEmbedView extends MPBaseEmbedView {
···
@Override
public void onReceivedMessage(String actionType, JSONObject data, H5BridgeContext bridgeContext) {
LoggerFactory.getTraceLogger().debug(TAG, "onReceivedMessage, actionType: " + actionType + ", data: " + data.toString());
if("setColor".equals(actionType)){
mRealView.setColor(Color.parseColor(data.getString("color")));
}
}
···
}
onReceivedMessage
方法中第一个参数为小程序传入的 actionType
,第二个参数为传入的扩展参数,第三个参数为 bridge
(可忽略)。