Kaynağa Gözat

部分修改

linbing 5 yıl önce
ebeveyn
işleme
94e504b8de

+ 2 - 2
.packages

@@ -1,4 +1,4 @@
-# Generated by pub on 2020-07-03 13:55:35.441391.
+# Generated by pub on 2020-07-16 17:42:34.468634.
 _fe_analyzer_shared:file:///E:/work/flutter/flutter_windows_1.17.2-stable/flutter/.pub-cache/hosted/pub.flutter-io.cn/_fe_analyzer_shared-5.0.0/lib/
 analyzer:file:///E:/work/flutter/flutter_windows_1.17.2-stable/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.39.11/lib/
 archive:file:///E:/work/flutter/flutter_windows_1.17.2-stable/flutter/.pub-cache/hosted/pub.flutter-io.cn/archive-2.0.13/lib/
@@ -67,4 +67,4 @@ watcher:file:///E:/work/flutter/flutter_windows_1.17.2-stable/flutter/.pub-cache
 web_socket_channel:file:///E:/work/flutter/flutter_windows_1.17.2-stable/flutter/.pub-cache/hosted/pub.flutter-io.cn/web_socket_channel-1.1.0/lib/
 xml:file:///E:/work/flutter/flutter_windows_1.17.2-stable/flutter/.pub-cache/hosted/pub.flutter-io.cn/xml-3.6.1/lib/
 yaml:file:///E:/work/flutter/flutter_windows_1.17.2-stable/flutter/.pub-cache/hosted/pub.flutter-io.cn/yaml-2.2.1/lib/
-flutter_tool_base:lib/
+flutter_aliyun_push:lib/

+ 99 - 0
android/app/src/main/kotlin/com/flutter/aliyunPush/AliyunPushPlugin.java

@@ -0,0 +1,99 @@
+package com.flutter.aliyunPush;
+
+import android.content.Context;
+
+import androidx.annotation.NonNull;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+
+import io.flutter.Log;
+import io.flutter.embedding.engine.plugins.FlutterPlugin;
+import io.flutter.plugin.common.BinaryMessenger;
+import io.flutter.plugin.common.JSONMethodCodec;
+import io.flutter.plugin.common.MethodCall;
+import io.flutter.plugin.common.MethodChannel;
+import io.flutter.plugin.common.PluginRegistry;
+
+public class AliyunPushPlugin implements FlutterPlugin, MethodChannel.MethodCallHandler {
+
+    private static AliyunPushPlugin instance;
+    private final String TAG = "AliyunPushPlugin";
+    private Context context;
+    private Object initializationLock = new Object();
+    private MethodChannel aliyunPushPluginChannel;
+
+    public AliyunPushPlugin() {}
+
+    public static void registerWith(PluginRegistry.Registrar registrar) {
+        if (instance == null) {
+            instance = new AliyunPushPlugin();
+        }
+        instance.onAttachedToEngine(registrar.context(), registrar.messenger());
+    }
+
+    @Override
+    public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
+        onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
+    }
+
+    @Override
+    public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
+        Log.i(TAG, "onDetachedFromEngine");
+        context = null;
+        aliyunPushPluginChannel.setMethodCallHandler(null);
+        aliyunPushPluginChannel = null;
+    }
+
+
+    public void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger) {
+        synchronized (initializationLock) {
+            if (aliyunPushPluginChannel != null) {
+                return;
+            }
+
+            Log.i(TAG, "onAttachedToEngine");
+            this.context = applicationContext;
+
+            // alarmManagerPluginChannel is the channel responsible for receiving the following messages
+            // from the main Flutter app:
+            // - "AlarmService.start"
+            // - "Alarm.oneShotAt"
+            // - "Alarm.periodic"
+            // - "Alarm.cancel"
+            aliyunPushPluginChannel =
+                    new MethodChannel(
+                            messenger, "com.flutter.plugins.aliyun_push", JSONMethodCodec.INSTANCE);
+
+            // Instantiate a new Plugin and connect the primary method channel for
+            // Android/Flutter communication.
+            aliyunPushPluginChannel.setMethodCallHandler(this);
+            aliyunPushPluginChannel.invokeMethod("onPushInit",null);
+
+        }
+    }
+
+    @Override
+    public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
+        String method = call.method;
+        Object arguments = call.arguments;
+        try {
+            if (method.equals("AlarmService.start")) {
+                // This message is sent when the Dart side of this plugin is told to initialize.
+                long callbackHandle = ((JSONArray) arguments).getLong(0);
+                // In response, this (native) side of the plugin needs to spin up a background
+                // Dart isolate by using the given callbackHandle, and then setup a background
+                // method channel to communicate with the new background isolate. Once completed,
+                // this onMethodCall() method will receive messages from both the primary and background
+                // method channels.
+                result.success(true);
+            }else {
+                result.notImplemented();
+            }
+        } catch (JSONException e) {
+            result.error("error", "JSON error: " + e.getMessage(), null);
+        } catch (Exception e) {
+            result.error("error", "AlarmManager error: " + e.getMessage(), null);
+        }
+    }
+}

+ 17 - 0
android/app/src/main/kotlin/com/flutter/aliyunPush/MainActivity.java

@@ -0,0 +1,17 @@
+package com.flutter.aliyunPush;
+
+import android.os.Bundle;
+
+import androidx.annotation.Nullable;
+
+import io.flutter.app.FlutterActivity;
+
+
+public class MainActivity extends FlutterActivity {
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+    }
+}

+ 20 - 0
android/app/src/main/kotlin/com/flutter/aliyunPush/MyApplication.java

@@ -0,0 +1,20 @@
+package com.flutter.aliyunPush;
+
+import io.flutter.app.FlutterApplication;
+import io.flutter.embedding.engine.FlutterEngine;
+import io.flutter.plugin.common.PluginRegistry;
+import io.flutter.plugins.GeneratedPluginRegistrant;
+
+public class MyApplication extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+    }
+
+    @Override
+    public void registerWith(PluginRegistry registry) {
+        AliyunPushPlugin.registerWith(
+                registry.registrarFor("com.flutter.aliyunPush.AliyunPushPlugin"));
+    }
+}

+ 0 - 6
android/app/src/main/kotlin/com/flutter/flutter_pager_list/MainActivity.kt

@@ -1,6 +0,0 @@
-package com.flutter.flutter_pager_list
-
-import io.flutter.embedding.android.FlutterActivity
-
-class MainActivity: FlutterActivity() {
-}

+ 3 - 3
pubspec.yaml

@@ -1,7 +1,7 @@
-name: flutter_tool_base
-description: a simple tool lib use some convenient tool
+name: flutter_aliyun_push
+description: 阿里云推送,支持安卓厂商通道
 version: 0.0.1
-homepage: https://github.com/linbing520/flutter_tool_base
+homepage: https://github.com/linbing520/flutter_aliyun_push
 
 # The following line prevents the package from being accidentally published to
 # pub.dev using `pub publish`. This is preferred for private packages.

+ 1 - 1
test/widget_test.dart

@@ -8,7 +8,7 @@
 import 'package:flutter/material.dart';
 import 'package:flutter_test/flutter_test.dart';
 
-import 'package:flutter_simple_tabbar/main.dart';
+import 'package:flutter_aliyun_push/main.dart';
 
 void main() {
   testWidgets('Counter increments smoke test', (WidgetTester tester) async {