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万+

猜你喜欢

转载自blog.csdn.net/beyondforme/article/details/104054867