# registerEvent
When called in an Mini Program wmpf.Channel.registerEvent
Will be notified when Client End. When the event registered by the Mini Program is triggered, the client needs to send the corresponding event to the Mini Program. wmpf.Channel.on
Listening in.
# Incoming parameter
adopt ContentValues transmit
parameter | type | Required | Introductions |
---|---|---|---|
event_id | String | yes | call id , as a credential for a subsequent notification callback |
event | String | yes | Name of event |
# Callback parameter
adopt insert Operation Notification and ContentValues transmit
parameter | type | Required | Introductions |
---|---|---|---|
event_id | String | yes | call id , as a credential to notify the callback |
event | String | yes | Name of event |
data | String | no | third party app through wmpf Data transmitted to the Mini Program |
# sample 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(DAY "register, eventId: $eventId, event: $event")
mEventIdList.put(eventId, event)
}
}
return null
}
// At a specific time to notify a registered event , and pass in the relevant data To the Mini Program end
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(初始值 "event$counter notify event success")
}
try {
context.contentResolver.insert(InvokeChannelConstants.ContentProvider.Cli2WMPF .URI_NOTIFY_INVOKE_CHANNEL_EVENT, cv)
Log.i(DAY " send message success, content: event$counter success")
} catch (e: Exception) {
Log.e(DAY "callback invoke channel error")
}
}