diff --git a/android/build.gradle b/android/build.gradle index 8143843..b27d712 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,7 +5,7 @@ buildscript { repositories { google() jcenter() - maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} +// maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} flatDir { dirs 'libs' } diff --git a/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java b/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java index e2b87c4..bd2e5cc 100644 --- a/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java +++ b/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java @@ -1,15 +1,12 @@ package com.wxwx.flutter_alibc; -import android.text.TextUtils; import android.util.Log; -import android.webkit.WebChromeClient; -import android.webkit.WebViewClient; -import android.widget.Toast; import android.content.Intent; import com.ali.auth.third.core.model.Session; +import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.PluginRegistry.Registrar; import io.flutter.plugin.common.MethodChannel.Result; @@ -17,8 +14,6 @@ import io.flutter.plugin.common.MethodCall; import java.util.HashMap; -import android.app.AlertDialog; - import static com.ali.auth.third.core.context.KernelContext.getApplicationContext; import static com.wxwx.flutter_alibc.PluginConstants.*; import static com.wxwx.flutter_alibc.PluginUtil.*; @@ -48,21 +43,27 @@ import java.util.Map; **/ public class FlutterAlibcHandle { - private static FlutterAlibcHandle handle; + private MethodChannel channel; + +// private static FlutterAlibcHandle handle; private static Registrar register; private static boolean isFirst = true; private static Result result; - //第一次调用getInstance register不能为空 - public static FlutterAlibcHandle getInstance(Registrar register) { - - synchronized (FlutterAlibcHandle.class) { - handle = new FlutterAlibcHandle(); - FlutterAlibcHandle.register = register; - } - return handle; + public FlutterAlibcHandle(MethodChannel channel) { + this.channel = channel; } + //第一次调用getInstance register不能为空 +// public static FlutterAlibcHandle getInstance(Registrar register) { +// +// synchronized (FlutterAlibcHandle.class) { +// handle = new FlutterAlibcHandle(); +// FlutterAlibcHandle.register = register; +// } +// return handle; +// } + /** * 初始化阿里百川 * diff --git a/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcPlugin.java b/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcPlugin.java index b97029c..53ec7fa 100644 --- a/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcPlugin.java +++ b/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcPlugin.java @@ -1,24 +1,40 @@ package com.wxwx.flutter_alibc; + +import androidx.annotation.NonNull; + +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 io.flutter.plugin.common.PluginRegistry.Registrar; /** FlutterAlibcPlugin */ -public class FlutterAlibcPlugin implements MethodCallHandler { +public class FlutterAlibcPlugin implements FlutterPlugin, MethodChannel.MethodCallHandler { - private static com.wxwx.flutter_alibc.FlutterAlibcHandle handle; +// private static com.wxwx.flutter_alibc.FlutterAlibcHandle handle; /** Plugin registration. */ - public static void registerWith(Registrar registrar) { - handle = com.wxwx.flutter_alibc.FlutterAlibcHandle.getInstance(registrar); - final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_alibc"); - channel.setMethodCallHandler(new FlutterAlibcPlugin()); +// public static void registerWith(Registrar registrar) { +// handle = com.wxwx.flutter_alibc.FlutterAlibcHandle.getInstance(registrar); +// final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_alibc"); +// channel.setMethodCallHandler(new FlutterAlibcPlugin()); +// } + private MethodChannel channel; + private com.wxwx.flutter_alibc.FlutterAlibcHandle handle; + + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "zhiying_live_ali"); + channel.setMethodCallHandler(this); + handle = new FlutterAlibcHandle(channel); + } + + + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); } @Override - public void onMethodCall(MethodCall call, Result result) { + public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { if (call.method.equals("getPlatformVersion")) { result.success("Android " + android.os.Build.VERSION.RELEASE); } else if (call.method.equals("initAlibc")){ diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 892db97..4d7fca9 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_alibc","path":"/Users/fnuouser/Documents/code/zhiying/zhiying_flutter_alibc/","dependencies":[]}],"android":[{"name":"flutter_alibc","path":"/Users/fnuouser/Documents/code/zhiying/zhiying_flutter_alibc/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_alibc","dependencies":[]}],"date_created":"2022-03-30 14:23:23.445986","version":"2.10.3"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_alibc","path":"/Users/fnuouser/Documents/code/zhiying/zhiying_flutter_alibc/","dependencies":[]}],"android":[{"name":"flutter_alibc","path":"/Users/fnuouser/Documents/code/zhiying/zhiying_flutter_alibc/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_alibc","dependencies":[]}],"date_created":"2022-03-31 17:14:41.211674","version":"2.10.3"} \ No newline at end of file diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 6679005..8d2630e 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -8,7 +8,7 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> @@ -23,6 +23,7 @@ until Flutter renders its first frame. It can be removed if there is no splash screen (such as the default splash screen defined in @style/LaunchTheme). --> + diff --git a/example/android/app/src/main/java/wxwx/com/flutter_alibc_example/MainActivity.java b/example/android/app/src/main/java/wxwx/com/flutter_alibc_example/MainActivity.java index 94ed98d..d504549 100644 --- a/example/android/app/src/main/java/wxwx/com/flutter_alibc_example/MainActivity.java +++ b/example/android/app/src/main/java/wxwx/com/flutter_alibc_example/MainActivity.java @@ -1,13 +1,7 @@ package wxwx.com.flutter_alibc_example; -import android.os.Bundle; -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; +import io.flutter.embedding.android.FlutterActivity; public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + } diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml index 00fa441..6db4496 100644 --- a/example/android/app/src/main/res/values/styles.xml +++ b/example/android/app/src/main/res/values/styles.xml @@ -5,4 +5,8 @@ Flutter draws its first frame --> @drawable/launch_background + + diff --git a/example/android/build.gradle b/example/android/build.gradle index 28967cb..d81e0db 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,6 +1,7 @@ buildscript { repositories { google() + jcenter() } dependencies {