Browse Source

1.优化京东初始化SDK时报错的问题

tags/0.1.1
huaxuan 2 years ago
parent
commit
19f31fe762
1 changed files with 50 additions and 39 deletions
  1. +50
    -39
      android/src/main/java/com/jd/jdsdk/JdsdkPlugin.java

+ 50
- 39
android/src/main/java/com/jd/jdsdk/JdsdkPlugin.java View File

@@ -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() {

}
}
}

Loading…
Cancel
Save