Parcourir la source

优化

优化
linbing il y a 5 ans
Parent
commit
5c175aafac

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

@@ -43,8 +43,8 @@ public class FlutterAliyunPushPlugin implements FlutterPlugin, MethodChannel.Met
   private MethodChannel aliyunPushPluginChannel;
   private static String lastPushRegistSuccessMessage;
   private static String lastPushRegistErrorMessage;
-  private static boolean isPluginAttached; //插件是否被加载到flutter
-  private static boolean isFlutterInvokeInitPush; //flutter是否调用了初始化方法,用来判断flutter是否已经添加了method监听
+  public static boolean isPluginAttached; //插件是否被加载到flutter
+  public static boolean isFlutterInvokeInitPush; //flutter是否调用了初始化方法,用来判断flutter是否已经添加了method监听
   private static List<FlutterPushNotification> cachedNotifications = new ArrayList<FlutterPushNotification>(); //未传到dart的消息
   private static List<FlutterPushMessage> cachedMessages = new ArrayList<FlutterPushMessage>(); //未传到dart的消息
 
@@ -77,7 +77,7 @@ public class FlutterAliyunPushPlugin implements FlutterPlugin, MethodChannel.Met
 
 
   public static void sendPushNotification(Context context,FlutterPushNotification message) {
-    if(FlutterAliyunPushPlugin.isPluginAttached) {
+    if(FlutterAliyunPushPlugin.isFlutterInvokeInitPush) {
       EventBus.getDefault().post(new PushMessageEvent(PushMessageEvent.EVENT_onReceiverNotification,message));
     }else {
       Log.d(FlutterAliyunPushPlugin.TAG, "notification recevie not plugin not attach");
@@ -86,7 +86,7 @@ public class FlutterAliyunPushPlugin implements FlutterPlugin, MethodChannel.Met
   }
 
   public static void sendPushMessage(Context context,FlutterPushMessage message) {
-    if(FlutterAliyunPushPlugin.isPluginAttached) {
+    if(FlutterAliyunPushPlugin.isFlutterInvokeInitPush) {
       EventBus.getDefault().post(new PushMessageEvent(PushMessageEvent.EVENT_onReceiverMessage,message));
     }else {
       Log.d(FlutterAliyunPushPlugin.TAG, "message recevie not plugin not attach");

+ 10 - 0
android/src/main/java/com/flutter/flutter_aliyun_push/PopupPushActivity.java

@@ -39,13 +39,23 @@ public class PopupPushActivity extends AndroidPopupActivity {
     protected void onSysNoticeOpened(String title, String summary, Map<String, String> extMap) {
         Log.d(TAG,"OnMiPushSysNoticeOpened, title: " + title + ", content: " + summary + ", extMap: " + extMap);
 
+        if(FlutterAliyunPushPlugin.isPluginAttached) {
+            finish();
+        }
+
         FlutterPushNotification notification = new FlutterPushNotification();
         notification.title = title;
         notification.summary = summary;
         notification.extraMap = extMap;
         FlutterAliyunPushPlugin.sendPushNotification(getApplicationContext(),notification);
+        if(FlutterAliyunPushPlugin.isPluginAttached) {
+            return;
+        }
+
         Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
         startActivity(intent);
         finish();
     }
+
+
 }

+ 8 - 6
example/lib/main.dart

@@ -1,3 +1,5 @@
+import 'dart:convert';
+
 import 'package:flutter/material.dart';
 import 'dart:async';
 
@@ -35,21 +37,21 @@ class _MyAppState extends State<MyApp> {
     }
 
     FlutterAliyunPush.reigistOnRegistSuccess((msg){
-      platformVersion = msg;
-      setState(() {
-        _platformVersion = platformVersion;
-      });
+//      platformVersion = msg;
+//      setState(() {
+//        _platformVersion = platformVersion;
+//      });
     });
 
     FlutterAliyunPush.reigistOnReceiveNotification((msg){
-      platformVersion = msg.title;
+      platformVersion = json.encode(msg.toJson());
       setState(() {
         _platformVersion = platformVersion;
       });
     });
 
     FlutterAliyunPush.reigistOnReceiveMessage((msg){
-      platformVersion = msg.title;
+      platformVersion = json.encode(msg.toJson());
       setState(() {
         _platformVersion = platformVersion;
       });