当前位置:   article > 正文

flutter 调用原生安卓插件_Flutter知识点: Flutter与原生(Android)的交互

flutter 通过plugin 实现跳转原生页面

Flutter与原生的交互主要通过MethodChannel的方式

本文只列举两种形式的插件,掌握基础的插件写法,举一反三,例如我github项目中的高德定位,6.0以上权限申请等,还需要掌握iOS的的基础语言o c,swift才能编写iOS插件。

效果GIF

Channel.gif

从Flutter界面跳转到原生,且带参数

1. 实现插件

public class FlutterPluginJumpToAct implements MethodChannel.MethodCallHandler {

public static String CHANNEL = "com.jzhu.jump/plugin";

static MethodChannel channel;

private Activity activity;

private FlutterPluginJumpToAct(Activity activity) {

this.activity = activity;

}

public static void registerWith(PluginRegistry.Registrar registrar) {

channel = new MethodChannel(registrar.messenger(), CHANNEL);

FlutterPluginJumpToAct instance = new FlutterPluginJumpToAct(registrar.activity());

//setMethodCallHandler在此通道上接收方法调用的回调

channel.setMethodCallHandler(instance);

}

@Override

public void onMethodCall(MethodCall call, MethodChannel.Result result) {

//通过MethodCall可以获取参数和方法名,然后再寻找对应的平台业务,本案例做了2个跳转的业务

//接收来自flutter的指令oneAct

if (call.method.equals("oneAct")) {

//跳转到指定Activity

Intent intent = new Intent(activity, OneActivity.class);

act

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/669948
推荐阅读
相关标签
  

闽ICP备14008679号