The function of sending custom message to custom View is only supported in mPaaS 10.1.68.29 and later. When the current baseline version is lower than 10.1.68.29, please refer to mPaaS 10.1.68 upgrade guide to upgrade the baseline version to 10.1.68.29.
Create custom View context
'mpaas-map'
is the value of id
in the mini program tab, fill in your id here.
this.context = my.createMpaasCustomComponentContext('mpaas-map');
Send message to the client by context
actiontype
is the name of the message event received by the client and data
is the extension parameter.
this.context.postMessage({
actionType: 'setColor',
data: {
"color": "#FF00FF00"
}
});
Client receives message and processes native View
In the onReceivedMessage
method, the first parameter is the actionType
passed in by the mini program, the second parameter is the extension parameter passed in, and the third parameter is bridge
(can be ignored).
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")));
}
}
···
}