diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a6f35c..5bd3de5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,4 +12,8 @@ ## 0.0.4 +* update. + +## 0.0.4+1 + * update. \ No newline at end of file diff --git a/android/src/main/java/com/iotserv/flutter_oneshot/FlutterOneshotPlugin.java b/android/src/main/java/com/iotserv/flutter_oneshot/FlutterOneshotPlugin.java index 481c26c..d62d3e2 100644 --- a/android/src/main/java/com/iotserv/flutter_oneshot/FlutterOneshotPlugin.java +++ b/android/src/main/java/com/iotserv/flutter_oneshot/FlutterOneshotPlugin.java @@ -1,100 +1,71 @@ package com.iotserv.flutter_oneshot; -import android.app.Activity; -import android.net.wifi.WifiManager; -import android.util.Log; - import androidx.annotation.NonNull; +import com.winnermicro.smartconfig.ConfigType; +import com.winnermicro.smartconfig.IOneShotConfig; +import com.winnermicro.smartconfig.SmartConfigFactory; + +import java.util.HashMap; +import java.util.Map; + import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import com.winnermicro.smartconfig.*; - -import java.util.HashMap; -import java.util.Map; - -/** FlutterOneshotPlugin */ +/** + * FlutterOneshotPlugin + */ public class FlutterOneshotPlugin implements FlutterPlugin, MethodCallHandler { - /// The MethodChannel that will the communication between Flutter and native Android - /// - /// This local reference serves to register the plugin with the Flutter Engine and unregister it - /// when the Flutter Engine is detached from the Activity - private int timeout = 60;//miao - private FlutterPluginBinding myFlutterPluginBinding; - private MethodChannel channel; + /// The MethodChannel that will the communication between Flutter and native Android + /// + /// This local reference serves to register the plugin with the Flutter Engine and unregister it + /// when the Flutter Engine is detached from the Activity + private int timeout = 60;//miao + private FlutterPluginBinding myFlutterPluginBinding; + private MethodChannel channel; - private String ssid; - private String password = null; - private IOneShotConfig oneshotConfig = null; - private SmartConfigFactory factory = null; + private String ssid; + private String password = null; + private IOneShotConfig oneshotConfig = null; + private SmartConfigFactory factory = null; - @Override - public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { - myFlutterPluginBinding = flutterPluginBinding; - channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_oneshot"); - channel.setMethodCallHandler(this); - } - - @Override - public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { - if (call.method.equals("getPlatformVersion")) { - result.success("Android " + android.os.Build.VERSION.RELEASE); - } else if (call.method.equals("start")){ - //参数获取 - ssid = call.argument("ssid"); - password = call.argument("password"); - try { - timeout = call.argument("timeout"); - }catch (Exception e){ - e.printStackTrace(); - timeout = 30; - } - new Thread(new UDPReqThread(result)).start(); - } - else { - result.notImplemented(); + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { + myFlutterPluginBinding = flutterPluginBinding; + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_oneshot"); + channel.setMethodCallHandler(this); } - } - - @Override - public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { - channel.setMethodCallHandler(null); - } - class UDPReqThread implements Runnable { - private Result result; - public UDPReqThread(Result result) - { - this.result = result; + @Override + public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { + if (call.method.equals("getPlatformVersion")) { + result.success("Android " + android.os.Build.VERSION.RELEASE); + } else if (call.method.equals("start")) { + //参数获取 + ssid = call.argument("ssid"); + password = call.argument("password"); + try { + timeout = call.argument("timeout"); + } catch (Exception e) { + e.printStackTrace(); + timeout = 30; + } + factory = new SmartConfigFactory(); + oneshotConfig = factory.createOneShotConfig(ConfigType.UDP); + oneshotConfig.start(ssid, password, timeout, myFlutterPluginBinding.getApplicationContext()); + final Map ret = new HashMap(); + ret.put("result", "success"); + result.success(ret); + } else { + result.notImplemented(); + } } - public void run() { - final Map ret = new HashMap(); - factory = new SmartConfigFactory(); - oneshotConfig = factory.createOneShotConfig(ConfigType.UDP); - // start config - try { - oneshotConfig.start(ssid, password, timeout, myFlutterPluginBinding.getApplicationContext()); - } - catch (OneShotException e) { - Log.d("===oneshot-OneShotE===",e.getMessage()); - e.printStackTrace(); - int code = e.getErrorID(); - Log.d("onshot err", String.valueOf(code)); - } - catch (Exception e) { - Log.d("===oneshot-exception===",e.getMessage()); - e.printStackTrace(); - } finally { - oneshotConfig.stop( ); - ret.put("result","success"); - Log.d("===oneshot-success===","success"); - result.success(ret); - } + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); } - } } diff --git a/pubspec.yaml b/pubspec.yaml index 3d6650d..29d6c74 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_oneshot description: OneShot for w60x wifi config -version: 0.0.4 +version: 0.0.4+1 homepage: https://github.com/iotdevice/flutter_oneshot environment: