Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
io.flutter.plugin.common.BinaryMessenger Interface Reference
Inheritance diagram for io.flutter.plugin.common.BinaryMessenger:
io.flutter.embedding.engine.dart.DartExecutor io.flutter.embedding.engine.dart.DartMessenger io.flutter.view.FlutterNativeView io.flutter.view.FlutterView

Classes

interface  BinaryMessageHandler
 
interface  BinaryReply
 
interface  TaskQueue
 
class  TaskQueueOptions
 

Public Member Functions

default TaskQueue makeBackgroundTaskQueue ()
 
default TaskQueue makeBackgroundTaskQueue (TaskQueueOptions options)
 
void send (@NonNull String channel, @Nullable ByteBuffer message)
 
void send (@NonNull String channel, @Nullable ByteBuffer message, @Nullable BinaryReply callback)
 
void setMessageHandler (@NonNull String channel, @Nullable BinaryMessageHandler handler)
 
default void setMessageHandler ( @NonNull String channel, @Nullable BinaryMessageHandler handler, @Nullable TaskQueue taskQueue)
 
default void enableBufferingIncomingMessages ()
 
default void disableBufferingIncomingMessages ()
 

Detailed Description

Facility for communicating with Flutter using asynchronous message passing with binary messages. The Flutter Dart code should use BinaryMessages to participate.

BinaryMessenger is expected to be utilized from a single thread throughout the duration of its existence. If created on the main thread, then all invocations should take place on the main thread. If created on a background thread, then all invocations should take place on that background thread.

See also
BasicMessageChannel , which supports message passing with Strings and semi-structured messages.
MethodChannel , which supports communication using asynchronous method invocation.
EventChannel , which supports communication using event streams.

Definition at line 28 of file BinaryMessenger.java.

Member Function Documentation

◆ disableBufferingIncomingMessages()

default void io.flutter.plugin.common.BinaryMessenger.disableBufferingIncomingMessages ( )
inline

Disables the ability to queue messages received from Dart.

This can be used after all pending channel handlers have been registered.

Implemented in io.flutter.embedding.engine.dart.DartExecutor, io.flutter.embedding.engine.dart.DartMessenger, io.flutter.view.FlutterNativeView, and io.flutter.view.FlutterView.

Definition at line 168 of file BinaryMessenger.java.

168 {
169 throw new UnsupportedOperationException("disableBufferingIncomingMessages not implemented.");
170 }

◆ enableBufferingIncomingMessages()

default void io.flutter.plugin.common.BinaryMessenger.enableBufferingIncomingMessages ( )
inline

Enables the ability to queue messages received from Dart.

This is useful when there are pending channel handler registrations. For example, Dart may be initialized concurrently, and prior to the registration of the channel handlers. This implies that Dart may start sending messages while plugins are being registered.

Implemented in io.flutter.embedding.engine.dart.DartExecutor, io.flutter.embedding.engine.dart.DartMessenger, io.flutter.view.FlutterNativeView, and io.flutter.view.FlutterView.

Definition at line 159 of file BinaryMessenger.java.

159 {
160 throw new UnsupportedOperationException("enableBufferingIncomingMessages not implemented.");
161 }

◆ makeBackgroundTaskQueue() [1/2]

default TaskQueue io.flutter.plugin.common.BinaryMessenger.makeBackgroundTaskQueue ( )
inline

Creates a TaskQueue that executes the tasks serially on a background thread.

There is no guarantee that the tasks will execute on the same thread, just that execution is serial. This is could be problematic if your code relies on ThreadLocal storage or introspection about what thread is actually executing.

Definition at line 67 of file BinaryMessenger.java.

67 {
68 return makeBackgroundTaskQueue(new TaskQueueOptions());
69 }

◆ makeBackgroundTaskQueue() [2/2]

default TaskQueue io.flutter.plugin.common.BinaryMessenger.makeBackgroundTaskQueue ( TaskQueueOptions  options)
inline

Creates a TaskQueue that executes the tasks serially on a background thread.

TaskQueueOptions can be used to configure the task queue to execute tasks concurrently. Doing so can be more performant, though users need to ensure that the task handlers are thread-safe.

Implemented in io.flutter.embedding.engine.dart.DartExecutor, io.flutter.embedding.engine.dart.DartMessenger, io.flutter.view.FlutterNativeView, and io.flutter.view.FlutterView.

Definition at line 79 of file BinaryMessenger.java.

79 {
80 // TODO(92582): Remove default implementation when it is safe for Google Flutter users.
81 throw new UnsupportedOperationException("makeBackgroundTaskQueue not implemented.");
82 }

◆ send() [1/2]

void io.flutter.plugin.common.BinaryMessenger.send ( @NonNull String  channel,
@Nullable ByteBuffer  message 
)

Sends a binary message to the Flutter application.

Parameters
channelthe name String of the logical channel used for the message.
messagethe message payload, a direct-allocated ByteBuffer with the message bytes between position zero and current position, or null.

Implemented in io.flutter.embedding.engine.dart.DartExecutor.

◆ send() [2/2]

void io.flutter.plugin.common.BinaryMessenger.send ( @NonNull String  channel,
@Nullable ByteBuffer  message,
@Nullable BinaryReply  callback 
)

Sends a binary message to the Flutter application, optionally expecting a reply.

Any uncaught exception thrown by the reply callback will be caught and logged.

Parameters
channelthe name String of the logical channel used for the message.
messagethe message payload, a direct-allocated ByteBuffer with the message bytes between position zero and current position, or null.
callbacka BinaryReply callback invoked when the Flutter application responds to the message, possibly null.

◆ setMessageHandler() [1/2]

default void io.flutter.plugin.common.BinaryMessenger.setMessageHandler ( @NonNull String  channel,
@Nullable BinaryMessageHandler  handler,
@Nullable TaskQueue  taskQueue 
)
inline

Registers a handler to be invoked when the Flutter application sends a message to its host platform.

Registration overwrites any previous registration for the same channel name. Use a null handler to deregister.

If no handler has been registered for a particular channel, any incoming message on that channel will be handled silently by sending a null reply.

Parameters
channelthe name String of the channel.
handlera BinaryMessageHandler to be invoked on incoming messages, or null.
taskQueuea BinaryMessenger.TaskQueue that specifies what thread will execute the handler. Specifying null means execute on the platform thread.

Definition at line 140 of file BinaryMessenger.java.

143 {
144 // TODO(92582): Remove default implementation when it is safe for Google Flutter users.
145 if (taskQueue != null) {
146 throw new UnsupportedOperationException(
147 "setMessageHandler called with nonnull taskQueue is not supported.");
148 }
149 setMessageHandler(channel, handler);
150 }
void setMessageHandler(@NonNull String channel, @Nullable BinaryMessageHandler handler)

◆ setMessageHandler() [2/2]

void io.flutter.plugin.common.BinaryMessenger.setMessageHandler ( @NonNull String  channel,
@Nullable BinaryMessageHandler  handler 
)

Registers a handler to be invoked when the Flutter application sends a message to its host platform.

Registration overwrites any previous registration for the same channel name. Use a null handler to deregister.

If no handler has been registered for a particular channel, any incoming message on that channel will be handled silently by sending a null reply.

Parameters
channelthe name String of the channel.
handlera BinaryMessageHandler to be invoked on incoming messages, or null.

The documentation for this interface was generated from the following file: