Explorar el Código

安卓功能修改

linbing hace 5 años
padre
commit
498ee6bc68

+ 2 - 1
android/src/main/java/com/flutter/flutter_aliyun_push/FlutterAliyunPushPlugin.java

@@ -66,7 +66,8 @@ public class FlutterAliyunPushPlugin implements FlutterPlugin, MethodChannel.Met
     ) {
       //初始化
       aliyunPushPluginChannel.invokeMethod(event.eventName,(String)event.params);
-    }else if(PushMessageEvent.EVENT_onReceiverMessage.equals(event.eventName)) {
+    }else if(PushMessageEvent.EVENT_onReceiverMessage.equals(event.eventName)
+    || PushMessageEvent.EVENT_onReceiverNotification.equals(event.eventName)) {
       //接受消息
       aliyunPushPluginChannel.invokeMethod(event.eventName,event.getParamsJSONString());
     }

+ 13 - 0
example/lib/main.dart

@@ -36,10 +36,23 @@ class _MyAppState extends State<MyApp> {
 
     FlutterAliyunPush.reigistOnRegistSuccess((msg){
       platformVersion = msg;
+      setState(() {
+        _platformVersion = platformVersion;
+      });
     });
 
     FlutterAliyunPush.reigistOnReceiveNotification((msg){
       platformVersion = msg.title;
+      setState(() {
+        _platformVersion = platformVersion;
+      });
+    });
+
+    FlutterAliyunPush.reigistOnReceiveMessage((msg){
+      platformVersion = msg.title;
+      setState(() {
+        _platformVersion = platformVersion;
+      });
     });
 
     // If the widget was removed from the tree while the asynchronous platform

+ 19 - 7
lib/flutter_aliyun_push.dart

@@ -1,6 +1,10 @@
 import 'dart:async';
-
+import 'dart:convert';
 import 'package:flutter/services.dart';
+import 'push_message.dart';
+
+typedef OnReceiveMessage = Function(PushMessage);
+typedef OnReceiveNotification = Function(PushNotification);
 
 class FlutterAliyunPush {
   static const MethodChannel _channel =
@@ -9,8 +13,8 @@ class FlutterAliyunPush {
 
   static Function onRegistSuccess;
   static Function onRegistError;
-  static Function onReceiveNotification;
-  static Function onReceiveMessage;
+  static OnReceiveNotification onReceiveNotification;
+  static OnReceiveMessage onReceiveMessage;
 
   static Future<String> get platformVersion async {
     final String version = await _channel.invokeMethod('getPlatformVersion');
@@ -45,12 +49,20 @@ class FlutterAliyunPush {
           break;
         case "onReceiverNotification":
           if(onReceiveNotification != null) {
-            onReceiveNotification(call.arguments);
+            var param = call.arguments;
+            if(param != null) {
+              param = PushNotification.fromJson(json.decode(param));
+            }
+            onReceiveNotification(param);
           }
           break;
         case "onReceiverMessage":
           if(onReceiveMessage != null) {
-            onReceiveMessage(call.arguments);
+            var param = call.arguments;
+            if(param != null) {
+              param = PushMessage.fromJson(json.decode(param));
+            }
+            onReceiveMessage(param);
           }
           break;
       }
@@ -68,12 +80,12 @@ class FlutterAliyunPush {
     registCallHandler();
   }
 
-  static void  reigistOnReceiveNotification(Function callback) {
+  static void  reigistOnReceiveNotification(OnReceiveNotification callback) {
     onReceiveNotification = callback;
     registCallHandler();
   }
 
-  static void  reigistOnReceiveMessage(Function callback) {
+  static void  reigistOnReceiveMessage(OnReceiveMessage callback) {
     onReceiveMessage = callback;
     registCallHandler();
   }

+ 57 - 0
lib/push_message.dart

@@ -0,0 +1,57 @@
+
+
+  class PushMessage extends Object {
+
+    String messageId;
+    String appId;
+    String title;
+    String content;
+    String traceInfo;
+
+  PushMessage(this.messageId,this.appId,this.title,this.content,this.traceInfo,);
+
+  PushMessage.fromJson(Map<String, dynamic> json)
+        : messageId = json['messageId'],
+          appId = json['appId'],
+          title = json['title'],
+          content = json['content'],
+          traceInfo = json['traceInfo'];
+
+    Map<String, dynamic> toJson() =>
+        {
+          'messageId': messageId,
+          'appId': appId,
+          'title': title,
+          'content': content,
+          'traceInfo': traceInfo,
+        };
+
+}
+
+
+  class PushNotification extends Object {
+
+    String title;
+    String summary;
+    Map<String, dynamic> extraMap;
+
+    PushNotification(this.title,this.summary,this.extraMap);
+
+    PushNotification.fromJson(Map<String, dynamic> json)
+        : title = json['title'],
+          summary = json['summary'],
+          extraMap = json['extraMap'];
+
+    Map<String, dynamic> toJson() =>
+        {
+          'title': title,
+          'summary': summary,
+          'extraMap': extraMap,
+        };
+
+  }
+  
+
+
+
+