registerEvent

View Markdown

Last edited on 2026-04-06

When wmpf.Channel.registerEvent is invoked in Mini Program, the Client is notified. When an event registered by Mini Program is triggered, the Client must send the corresponding event to Mini Program, which can be monitored via wmpf.Channel.on.

Input Parameters

Passed via ContentValues

Parameter Type Required Description
__event_id__ String Yes The call ID, used as a credential for subsequent notification callbacks
event String Yes Event name

Callback Parameters

Passed via insert operation notification and ContentValues

Parameter Type Required Description
__event_id__ String Yes Call ID, used as the credential for the notification callback
event String Yes Event name
data String No Data from the third-party app passed through wmpf to Mini Program

Example Code

override fun insert(p0: Uri, p1: ContentValues?): Uri? {
 when(sURIMatcher.match(p0)) {
 // Callback event registration
 CODE_NOTIFY_INVOKE_CHANNEL_EVENT -> {
 val eventId = p1?.getAsString(InvokeChannelConstants.Key.EVENT_ID)
 val event = p1?.getAsString(InvokeChannelConstants.Key.EVENT)
 Log.i(TAG, "register, eventId: $eventId, event: $event")
 mEventIdList.put(eventId, event)
}
}
 return null
}

// Notify a specific registered event at a specific timing, and pass related data to the Mini Program side
private fun notifyEvent(counter: Int, eventId: String?, event: String?) {
 if (!mEventIdList.containsKey(eventId)) {
 return 
}
 val cv = ContentValues()
 cv.apply {
 put(InvokeChannelConstants.Key.EVENT_ID, eventId)
 put(InvokeChannelConstants.Key.EVENT, event)
 put(InvokeChannelConstants.Key.DATA, "event$counter notify event success")
}
 try {
 context.contentResolver.insert(InvokeChannelConstants.ContentProvider.Cli2WMPF.URI_NOTIFY_INVOKE_CHANNEL_EVENT, cv)
 Log.i(TAG, "send message success, content: event$counter success")
} catch (e: Exception) {
 Log.e(TAG, "callback invoke channel error")
}
}