5package io.flutter.plugin.common;
7import androidx.annotation.NonNull;
8import androidx.annotation.Nullable;
9import androidx.annotation.UiThread;
10import io.flutter.BuildConfig;
12import io.flutter.plugin.common.BinaryMessenger.BinaryMessageHandler;
13import io.flutter.plugin.common.BinaryMessenger.BinaryReply;
14import java.nio.ByteBuffer;
30 private static final String TAG =
"MethodChannel#";
33 private final String name;
35 private final BinaryMessenger.TaskQueue taskQueue;
58 this(messenger, name, codec,
null);
78 if (messenger ==
null) {
79 Log.
e(
TAG,
"Parameter messenger must not be null.");
82 Log.
e(
TAG,
"Parameter name must not be null.");
85 Log.
e(
TAG,
"Parameter codec must not be null.");
88 this.messenger = messenger;
91 this.taskQueue = taskQueue;
101 public void invokeMethod(@NonNull String method, @Nullable Object arguments) {
116 @NonNull String method, @Nullable Object arguments, @Nullable
Result callback) {
142 if (taskQueue !=
null) {
144 name, handler ==
null ?
null :
new IncomingMethodCallHandler(handler), taskQueue);
147 name, handler ==
null ?
null :
new IncomingMethodCallHandler(handler));
223 @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails);
229 private final class IncomingResultHandler
implements BinaryReply {
238 public void reply(ByteBuffer reply) {
245 }
catch (FlutterException
e) {
249 }
catch (RuntimeException
e) {
250 Log.e(TAG + name,
"Failed to handle method call result",
e);
259 this.handler = handler;
267 handler.onMethodCall(
271 public void success(Object
result) {
276 public void error(String errorCode, String errorMessage, Object errorDetails) {
281 public void notImplemented() {
285 }
catch (RuntimeException
e) {
286 Log.e(TAG + name,
"Failed to handle method call",
e);
289 "error",
e.getMessage(),
null,
Log.getStackTraceString(
e)));
static final boolean DEBUG
static void e(@NonNull String tag, @NonNull String message)
void resizeChannelBuffer(int newSize)
void setWarnsOnChannelOverflow(boolean warns)
MethodChannel( @NonNull BinaryMessenger messenger, @NonNull String name, @NonNull MethodCodec codec, @Nullable BinaryMessenger.TaskQueue taskQueue)
MethodChannel( @NonNull BinaryMessenger messenger, @NonNull String name, @NonNull MethodCodec codec)
void setMethodCallHandler(final @Nullable MethodCallHandler handler)
void invokeMethod(@NonNull String method, @Nullable Object arguments)
void invokeMethod( @NonNull String method, @Nullable Object arguments, @Nullable Result callback)
void setWarnsOnChannelOverflow(boolean warns)
MethodChannel(@NonNull BinaryMessenger messenger, @NonNull String name)
void resizeChannelBuffer(int newSize)
static final StandardMethodCodec INSTANCE
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
const uint8_t uint32_t uint32_t GError ** error
void onMessage(@Nullable ByteBuffer message, @NonNull BinaryReply reply)
void setMessageHandler(@NonNull String channel, @Nullable BinaryMessageHandler handler)
void send(@NonNull String channel, @Nullable ByteBuffer message)
void onMethodCall(@NonNull MethodCall call, @NonNull Result result)
void success(@Nullable Object result)
void error( @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails)
ByteBuffer encodeSuccessEnvelope(@Nullable Object result)
ByteBuffer encodeErrorEnvelope( @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails)
ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall)
MethodCall decodeMethodCall(@NonNull ByteBuffer methodCall)
ByteBuffer encodeErrorEnvelopeWithStacktrace( @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails, @Nullable String errorStacktrace)
Object decodeEnvelope(@NonNull ByteBuffer envelope)
void Log(const char *format,...) SK_PRINTF_LIKE(1
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
std::function< void(const MethodCall< T > &call, std::unique_ptr< MethodResult< T > > result)> MethodCallHandler