add notification trigger controler.
authorTrillGates <williamtrillgates@gmail.com>
Tue, 31 Aug 2021 12:38:36 +0000 (20:38 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Tue, 31 Aug 2021 12:38:36 +0000 (20:38 +0800)
app/src/main/java/com/ic/launcher/presenter/MainPagePresenter.java

index 5047a17..0cfea76 100644 (file)
@@ -103,23 +103,47 @@ public class MainPagePresenter extends BasePresenter {
         mContext.registerReceiver(mScreenStateReceiver, intentFilter);
     }
 
+    public static final String KEY_NOTIFICATION_ENABLE = "key_notification_enable";
+
     public void checkNotification() {
+        //如果是关闭的,有多少删除多少
         executor.execute(() -> {
-            Cursor query = mContext.getContentResolver().query(Uri.parse(NOTIFICATIONS),
-                    null, null, null, null);
-            if (query != null) {
-                if (query.moveToNext()) {
-                    //判断当前是不是拨号在前,如果是的话,就不要弹出
-                    boolean isInCallUiTop = checkInCallUiTop();
-                    if (!isInCallUiTop) {
-                        mContext.startActivity(new Intent(mContext, NotificationActivity.class));
+            String notificationValue = getValue(KEY_NOTIFICATION_ENABLE);
+            ICLogger.d("notificationValue ==> " + notificationValue);
+            if (notificationValue == null || "1".equals(notificationValue)) {
+                Cursor query = mContext.getContentResolver().query(Uri.parse(NOTIFICATIONS),
+                        null, null, null, null);
+                if (query != null) {
+                    if (query.moveToNext()) {
+                        //判断当前是不是拨号在前,如果是的话,就不要弹出
+                        boolean isInCallUiTop = checkInCallUiTop();
+                        if (!isInCallUiTop) {
+                            mContext.startActivity(new Intent(mContext, NotificationActivity.class));
+                        }
                     }
+                    query.close();
                 }
-                query.close();
+            } else {
+                int delete = mContext.getContentResolver().delete(Uri.parse(NOTIFICATIONS), null, null);
+                ICLogger.d("notification delete count => " + delete);
             }
         });
     }
 
+
+    private String getValue(String key) {
+        Cursor query = mContext.getContentResolver()
+                .query(Uri.parse(SETTINGS), new String[]{"s_value"},
+                        "s_key=?", new String[]{key}, null);
+        if (query != null) {
+            if (query.moveToNext()) {
+                return query.getString(0);
+            }
+            query.close();
+        }
+        return null;
+    }
+
     private boolean checkInCallUiTop() {
         ArrayList<String> arrayList = new ArrayList();
         arrayList.add("com.android.incallui.InCallActivity");