update msg unread state listener.
authorTrillGates <williamtrillgates@gmail.com>
Mon, 19 Jul 2021 12:20:54 +0000 (20:20 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Mon, 19 Jul 2021 12:20:54 +0000 (20:20 +0800)
app/src/main/java/com/enqualcomm/support/ICSmsManager.java
app/src/main/java/com/enqualcomm/support/service/PhoneCallListener.java

index 2030687..abcefd9 100644 (file)
@@ -23,6 +23,7 @@ import com.enqualcomm.support.bean.ICLocation;
 import com.enqualcomm.support.bean.Runtime;
 import com.enqualcomm.support.bean.StringMessage;
 import com.enqualcomm.support.provider.ICDatabaseHelper;
+import com.enqualcomm.support.provider.ICGlobalSettingsProvider;
 import com.enqualcomm.support.provider.ICNotificationProvider;
 import com.enqualcomm.support.service.AudioService;
 import com.enqualcomm.support.service.Deliver;
@@ -159,9 +160,9 @@ public class ICSmsManager extends BroadcastReceiver {
                 }
             }
         }
-
     }
 
+
     private void updateMsgSettingsValue() {
         ContentValues contentValues = new ContentValues();
         //分类是心率的包名
@@ -169,7 +170,7 @@ public class ICSmsManager extends BroadcastReceiver {
         //1表示有,0表示没有
         contentValues.put(ICDatabaseHelper.sValue, 1);
         ContentResolver resolver = runtime.getContextProxy().getResolver();
-        resolver.insert(Uri.parse(ICNotificationProvider.NOTIFICATIONS), contentValues);
+        resolver.insert(Uri.parse(ICGlobalSettingsProvider.SETTINGS), contentValues);
     }
 
     private void createNotification(String title, String type) {
@@ -196,7 +197,6 @@ public class ICSmsManager extends BroadcastReceiver {
             }
             sendSMS(cell_number_to_reply, "http://maps.google.com/?q=" + locationResponseUrl);
             cell_number_to_reply = "";
-
         }
     }
 
index 8772e66..d5a0e25 100644 (file)
@@ -8,6 +8,7 @@ import android.net.Uri;
 import android.provider.CallLog;
 import android.telephony.PhoneStateListener;
 import android.telephony.ServiceState;
+import android.text.TextUtils;
 
 import com.enqualcomm.support.provider.ICDatabaseHelper;
 import com.enqualcomm.support.provider.ICNotificationProvider;
@@ -23,6 +24,7 @@ import static com.enqualcomm.support.provider.ICGlobalSettingsProvider.SETTINGS;
 public class PhoneCallListener extends PhoneStateListener {
 
     private final Context mContext;
+    private String mLastPhoneNumber;
 
     public PhoneCallListener(Context context) {
         this.mContext = context;
@@ -38,19 +40,26 @@ public class PhoneCallListener extends PhoneStateListener {
     public void onCallStateChanged(int state, String incomingNumber) {
         super.onCallStateChanged(state, incomingNumber);
         ICLogger.d("state == > " + state + " incomingNumber ==>  " + incomingNumber);
+        if (!TextUtils.isEmpty(incomingNumber)) {
+            this.mLastPhoneNumber = incomingNumber;
+        }
         //挂断的时候,去查询一下是不是未接电话即可
         if (state == CALL_STATE_IDLE) {
             //去查询是否有未接电话
-            queryCallState();
+            queryCallState(this.mLastPhoneNumber);
         }
     }
 
-    private void queryCallState() {
+    private void queryCallState(String phoneNum) {
+        if (TextUtils.isEmpty(phoneNum)) {
+            return;
+        }
         String[] projection = {
                 CallLog.Calls.NUMBER,
                 CallLog.Calls.TYPE
         };
-        String where = CallLog.Calls.TYPE + "=" + CallLog.Calls.MISSED_TYPE;
+        String where = CallLog.Calls.TYPE + "=" + CallLog.Calls.MISSED_TYPE + " and " +
+                CallLog.Calls.NUMBER + "=" + phoneNum;
         Cursor c = mContext.getContentResolver().query(
                 Uri.parse("content://call_log/calls"),
                 projection,
@@ -58,9 +67,9 @@ public class PhoneCallListener extends PhoneStateListener {
                 null,
                 null
         );
+        ICLogger.d("where is == > " + where);
         if (c != null) {
             if (c.moveToNext()) {
-                String phoneNum = c.getString(0);
                 //创建通知,如果大于1的知,说明有未接电话
                 createNotification(phoneNum);
                 //修改顶部的状态
@@ -79,6 +88,7 @@ public class PhoneCallListener extends PhoneStateListener {
     }
 
     private void createNotification(String phoneNum) {
+        ICLogger.d("createNotification==> " + phoneNum);
         ContentValues contentValues = new ContentValues();
         //分类是心率的包名
         contentValues.put(ICDatabaseHelper.notification_category, "com.ic.phone");