flutter 调用原生方法,返回桌面

开发xmpp中发现,flutter 有限功能还是无法实现的,就需要原生功能的实现

 

import android.os.Bundle;

import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;

import static com.example.wechat.VideoUtils.getLocalVideoThumbnail;
import static com.example.wechat.VideoUtils.getVideoThumbnail;


public class MainActivity extends FlutterActivity {

    //通讯名称,回到手机桌面
    private final String CHANNEL_DESKTOP = "android/back/desktop";
    //通讯名称,回到手机桌面
    private final String CHANNEL_VIDEO = "video/img";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        GeneratedPluginRegistrant.registerWith(this);
        new MethodChannel(getFlutterView(), CHANNEL_DESKTOP).setMethodCallHandler(
                (methodCall, result) -> {
                    if (methodCall.method.equals("backDesktop")) {
                        result.success(true);
                        moveTaskToBack(false);
                    } else {
                        result.notImplemented();
                    }
                }
        );
        new MethodChannel(getFlutterView(), CHANNEL_VIDEO).setMethodCallHandler((methodCall, result) -> {
            if (methodCall.method.equals("getNetVideoImg")) {
                result.success(getVideoThumbnail(methodCall.argument("path"),
                        methodCall.argument("name")));
            } else if (methodCall.method.equals("getLocalVideoImg")) {
                result.success(getLocalVideoThumbnail(methodCall.argument("path"),
                        methodCall.argument("name")));
            } else {
                result.notImplemented();
            }

        });
    }


}


更多详解:
喜欢可以加Q群号:913934649,点赞,评论;

简书: https://www.jianshu.com/u/88db5f15770d

csdn:https://me.csdn.net/beyondforme

掘金:https://juejin.im/user/5e09a9e86fb9a016271294a7

踏云归 发布了137 篇原创文章 · 获赞 18 · 访问量 5万+ 私信 关注

相关文章

这篇文章主要讲解了“FlutterComponent动画的显和隐怎么实现...
这篇文章主要讲解了“flutter微信聊天输入框功能如何实现”,...
本篇内容介绍了“Flutter之Navigator的高级用法有哪些”的有...
这篇文章主要介绍“Flutter怎么使用Android原生播放器”,在...
Flutter开发的android端如何修改APP名称,logo,版本号,具体...
Flutter路由管理初识路由概念一.路由管理1.1.Route1.2.Mater...