flutter和android 交互
普通交互用MethodChannel,持续性的用EventChannel,比如上传图片传递进度
new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
.setMethodCallHandler(
(call, result) -> {
}
);
new EventChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), EVENT_CHANNEL).setStreamHandler(new EventChannel.StreamHandler() {
@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
MainActivity.this.eventSink = eventSink;
// eventSink.success("事件通道准备就绪");
//在此不建议做耗时操作,因为当onListen回调被触发后,在此注册当方法需要执行完毕才算结束回调函数
//的执行,耗时操作可能会导致界面卡死,这里读者需注意!!
}
@Override
public void onCancel(Object o) {
}
});