私は、FlutterアプリでネイティブAndroidメソッドを使用していました。
MethodChannel(flutterView, CHANNEL).setMethodCallHandler...
しかし、Flutter をアップグレードした後は、その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
}
});
}
ベストアンサー1
getFlutterView()
と置換するgetFlutterEngine().getDartExecutor().getBinaryMessenger()
。
.getBinaryMessenger()
実際には、 asDartExecutor
実装自体は必要ではありませんBinaryMessenger
(転送するだけで) が、メッセンジャーを指定する方が正しいと思います。