From 19f31fe7624c0a2d3ec2646a4bbad91f59b35d81 Mon Sep 17 00:00:00 2001 From: huaxuan <646903573@qq.com> Date: Sat, 15 Oct 2022 14:43:28 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E4=BA=AC=E4=B8=9C=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96SDK=E6=97=B6=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/jd/jdsdk/JdsdkPlugin.java | 89 +++++++++++-------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/android/src/main/java/com/jd/jdsdk/JdsdkPlugin.java b/android/src/main/java/com/jd/jdsdk/JdsdkPlugin.java index 961d4cc..b922d0a 100644 --- a/android/src/main/java/com/jd/jdsdk/JdsdkPlugin.java +++ b/android/src/main/java/com/jd/jdsdk/JdsdkPlugin.java @@ -11,55 +11,66 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.PluginRegistry.Registrar; -/** JdsdkPlugin */ +/** + * JdsdkPlugin + */ public class JdsdkPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware { - public static JDHelper mJDHelper; - private MethodChannel channel; - @Override - public void onAttachedToEngine( FlutterPluginBinding flutterPluginBinding) { + public static JDHelper mJDHelper; + private MethodChannel channel; + + @Override + public void onAttachedToEngine(FlutterPluginBinding flutterPluginBinding) { // mJDHelper = JDHelper.getInstance(flutterPluginBinding.getApplicationContext()); - channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "jdsdk"); - channel.setMethodCallHandler(this); - } + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "jdsdk"); + channel.setMethodCallHandler(this); + } - @Override - public void onMethodCall( MethodCall call, Result result) { - if (call.method.equals("getPlatformVersion")) { - result.success("Android " + android.os.Build.VERSION.RELEASE); - } else if (call.method.equals("init")) { - mJDHelper.initKepler(call,result); - }else if (call.method.equals("openUrl")) { - Log.d("flutter-test","openUrl"); - mJDHelper.openUrl(call,result); - }else { - result.notImplemented(); + @Override + public void onMethodCall(MethodCall call, Result result) { + try { + if (mJDHelper == null) { + mJDHelper = JDHelper.getInstance(binding); + } + if (call.method.equals("getPlatformVersion")) { + result.success("Android " + android.os.Build.VERSION.RELEASE); + } else if (call.method.equals("init")) { + mJDHelper.initKepler(call, result); + } else if (call.method.equals("openUrl")) { + Log.d("flutter-test", "openUrl"); + mJDHelper.openUrl(call, result); + } else { + result.notImplemented(); + } + } catch (Exception e) { + Log.d("zhiying", "捕获出错"); + e.printStackTrace(); + } } - } - @Override - public void onDetachedFromEngine( FlutterPluginBinding binding) { - channel.setMethodCallHandler(null); - mJDHelper = null; - } + @Override + public void onDetachedFromEngine(FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); + mJDHelper = null; + } - @Override - public void onAttachedToActivity( ActivityPluginBinding binding) { - Log.d("flutter-taoke","onAttachedToActivity"+binding); - mJDHelper = JDHelper.getInstance(binding); - } + @Override + public void onAttachedToActivity(ActivityPluginBinding binding) { + Log.d("flutter-taoke", "onAttachedToActivity" + binding); + mJDHelper = JDHelper.getInstance(binding); + } - @Override - public void onDetachedFromActivityForConfigChanges() { + @Override + public void onDetachedFromActivityForConfigChanges() { - } + } - @Override - public void onReattachedToActivityForConfigChanges( ActivityPluginBinding binding) { + @Override + public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) { - } + } - @Override - public void onDetachedFromActivity() { + @Override + public void onDetachedFromActivity() { - } + } }