فهرست منبع

1.修改Android Apex Drivers通知为空处理。

Pen Li 7 سال پیش
والد
کامیت
e8f244d95c

+ 11 - 6
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/MainActivity.java

@@ -233,12 +233,17 @@ public class MainActivity extends BasicActivity implements LoginFragment.LoginCa
             if (notifications.length > 0) {
                 StatusBarNotification statusBarNotification = notifications[0];
                 Notification notification = statusBarNotification.getNotification();
-                try {
-                    Intent immutIntent = new Intent();
-                    immutIntent.putExtra("is_alert",true);
-                    notification.contentIntent.send(this,statusBarNotification.getId(),immutIntent);
-                } catch (PendingIntent.CanceledException e) {
-                    e.printStackTrace();
+                if (notification != null) {
+                    try {
+                        Intent immutIntent = new Intent();
+                        immutIntent.putExtra("is_alert",true);
+                        PendingIntent contentIntent = notification.contentIntent;
+                       if (contentIntent != null) {
+                           contentIntent.send(this,statusBarNotification.getId(),immutIntent);
+                       }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
                 }
             }
 

+ 15 - 10
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/receiver/ApexDriverAlarmReceiver.java

@@ -1,6 +1,7 @@
 package com.usai.redant.apexdrivers.receiver;
 
 import android.app.AlarmManager;
+import android.app.Application;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
@@ -158,21 +159,25 @@ public class ApexDriverAlarmReceiver extends AlarmReceiver {
             @Override
             public void run() {
 
-                JSONObject json = com.usai.redant.apexdrivers.network.Network.pullNotification();
+                if (ApexDriverApplication.sharedApplication().isLogin()) {
 
-                if (json != null) {
+                    JSONObject json = com.usai.redant.apexdrivers.network.Network.pullNotification();
 
-                    int result = json.optInt("result",0);
-                    if (result == RESULT_TRUE) {
+                    if (json != null) {
 
-                        JSONArray notifications = json.optJSONArray("notifications");
-                        if (notifications != null) {
+                        int result = json.optInt("result",0);
+                        if (result == RESULT_TRUE) {
 
-                            for (int i = 0; i < notifications.length(); i++) {
-                                JSONObject notification = notifications.optJSONObject(i);
-                                if (notification != null) {
-                                    ApexDriverApplication.sharedApplication().receiveNotificationOnMainThread(notification);
+                            JSONArray notifications = json.optJSONArray("notifications");
+                            if (notifications != null) {
+
+                                for (int i = 0; i < notifications.length(); i++) {
+                                    JSONObject notification = notifications.optJSONObject(i);
+                                    if (notification != null) {
+                                        ApexDriverApplication.sharedApplication().receiveNotificationOnMainThread(notification);
+                                    }
                                 }
+
                             }
 
                         }