android - 升级颤振后创建方法通道 - 无法解析方法 getFlutterView()
问题描述
我在我的颤振应用程序中使用原生 android 方法,使用文档说使用
MethodChannel(flutterView, CHANNEL).setMethodCallHandler...
但升级颤振后,该MethodChannel
功能不再需要flutterView
,也flutterView
不再存在。
can not resolve method getFlutterView()
我认为应该有一个创建频道的新教程
相反,它需要一些BinaryMessenger
我不知道该给的东西。
这是不再工作的旧代码:
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "samples.flutter.dev/battery";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, Result result) {
// Note: this method is invoked on the main thread.
// TODO
}
});
}
解决方案
替换getFlutterView()
为getFlutterEngine().getDartExecutor().getBinaryMessenger()
。
您实际上并不需要.getBinaryMessenger()
asDartExecutor
实现BinaryMessenger
本身(仅通过转发),但我认为指定信使更正确。
推荐阅读
- domain-driven-design - 如果认证涉及到一些业务逻辑,不应该去Domain Service吗?
- swiftui - 如何更改特定区域的工作表 DragGesture?
- typescript - 是否可以在同一个文件中多次使用“require”?
- angular - 尝试将 razorpay 与 angular9 集成时无法读取 null 的属性 postMessage
- c# - 有没有办法通过隐式转换在类实例中设置参数,就像 c# 中的运算符一样?
- pyqt - 如何在 python、PyQt 中读取文件/读取?
- angular - 如何刷新 MatTable 中的数据源?
- memory-management - 远程 Peer 如何处理 RDMA 写操作发送的数据
- c# - ASP .NET Core DI:向 HTTP 客户端提供异步 BaseAddress
- html - Bootstrap 4在手风琴面板中保持打开其他面板