public final class EventChannel extends Object
Incoming requests for event stream setup are decoded from binary on receipt, and Java
responses and events are encoded into binary before being transmitted back to Flutter. The MethodCodec
used must be compatible with the one used by the Flutter application. This can be
achieved by creating an EventChannel
counterpart of this channel on the Dart side. The Java type of stream configuration arguments,
events, and error details is Object
, but only values supported by the specified MethodCodec
can be used.
The logical identity of the channel is given by its name. Identically named channels will interfere with each other's communication.
Modifier and Type | Class and Description |
---|---|
static interface |
EventChannel.EventSink
Event callback.
|
static interface |
EventChannel.StreamHandler
Handler of stream setup and tear-down requests.
|
Constructor and Description |
---|
EventChannel(BinaryMessenger messenger,
String name)
Creates a new channel associated with the specified
BinaryMessenger and with the
specified name and the standard MethodCodec . |
EventChannel(BinaryMessenger messenger,
String name,
MethodCodec codec)
Creates a new channel associated with the specified
BinaryMessenger and with the
specified name and MethodCodec . |
Modifier and Type | Method and Description |
---|---|
void |
setStreamHandler(EventChannel.StreamHandler handler)
Registers a stream handler on this channel.
|
public EventChannel(BinaryMessenger messenger, String name)
BinaryMessenger
and with the
specified name and the standard MethodCodec
.messenger
- a BinaryMessenger
.name
- a channel name String.public EventChannel(BinaryMessenger messenger, String name, MethodCodec codec)
BinaryMessenger
and with the
specified name and MethodCodec
.messenger
- a BinaryMessenger
.name
- a channel name String.codec
- a MessageCodec
.@UiThread public void setStreamHandler(EventChannel.StreamHandler handler)
Overrides any existing handler registration for (the name of) this channel.
If no handler has been registered, any incoming stream setup requests will be handled silently by providing an empty stream.
handler
- a EventChannel.StreamHandler
, or null to deregister.