flutter 调用原生方法,返回桌面
2020-01-20 本文已影响0人
张漂亮1号
开发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();
}
});
}
}
image
更多详解:
喜欢可以加Q群号:913934649,点赞,评论;
简书: https://www.jianshu.com/u/88db5f15770d