flutter 调用 原生
1.实现插件
public class FlutterPluginTest implements MethodChannel.MethodCallHandler {
private static final String TAG = “FlutterPluginTest”;
/**
- 插件标识
*/
public static String CHANNEL = “com.mmd.flutterapp/plugin”;
private static String ACTION_LOG = “log”;
private static String LOG_ARGUMENT = “data”;
static MethodChannel channel;
public static void registerWith(PluginRegistry.Registrar registrar) {
channel = new MethodChannel(registrar.messenger(), CHANNEL);
FlutterPluginTest instance = new FlutterPluginTest();
channel.setMethodCallHandler(instance);
}
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
/**
- 通过 method 判断调用方法
*/
if (methodCall.method.equals(AC