flutter plugin try to see if these plugins support the Android V2 embedding

上官修文
2023-12-01
  1. import
import android.content.Context;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
  1. implements添加FlutterPlugin
  2. 添加以下代码,酌情修改
    static MethodChannel methodChannel;
    private Context applicationContext;
    @Override
    public void onAttachedToEngine(@NonNull FlutterPlugin.FlutterPluginBinding binding) {
        onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
    }

    private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger) {
        this.applicationContext = applicationContext;
        channel = new MethodChannel(messenger, "xx");
        channel.setMethodCallHandler(this);
    }


    @Override
    public void onDetachedFromEngine(@NonNull FlutterPlugin.FlutterPluginBinding binding) {
        applicationContext = null;
        channel.setMethodCallHandler(null);
        channel = null;
    }
  1. 修改registerWith
    final XXPlugin instance = new XXPlugin(registrar.activity());
    registrar.addActivityResultListener(instance);
    instance.onAttachedToEngine(registrar.context(), registrar.messenger());
  1. android/app/src/main/AndroidManifest.xml在application标签中添加以下内容
    <meta-data android:name="flutterEmbedding" android:value="2" />
  1. 大功告成
 类似资料:

相关阅读

相关文章

相关问答