diff --git a/app/src/main/java/com/idormy/sms/forwarder/SettingActivity.java b/app/src/main/java/com/idormy/sms/forwarder/SettingActivity.java index 61bfc09f..ca07b181 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/SettingActivity.java +++ b/app/src/main/java/com/idormy/sms/forwarder/SettingActivity.java @@ -75,7 +75,8 @@ public class SettingActivity extends AppCompatActivity { switchEnablePhone(switch_enable_phone); @SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_enable_app_notify = findViewById(R.id.switch_enable_app_notify); - switchEnableAppNotify(switch_enable_app_notify); + @SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_cancel_app_notify = findViewById(R.id.switch_cancel_app_notify); + switchEnableAppNotify(switch_enable_app_notify, switch_cancel_app_notify); @SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_exclude_from_recents = findViewById(R.id.switch_exclude_from_recents); switchExcludeFromRecents(switch_exclude_from_recents); @@ -121,10 +122,14 @@ public class SettingActivity extends AppCompatActivity { } //设置转发APP通知 - private void switchEnableAppNotify(@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_enable_app_notify) { - switch_enable_app_notify.setChecked(SettingUtil.getSwitchEnableAppNotify()); + private void switchEnableAppNotify(@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_enable_app_notify, @SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_cancel_app_notify) { + final LinearLayout layout_cancel_app_notify = findViewById(R.id.layout_cancel_app_notify); + boolean isEnable = SettingUtil.getSwitchEnableAppNotify(); + switch_enable_app_notify.setChecked(isEnable); + layout_cancel_app_notify.setVisibility(isEnable ? View.VISIBLE : View.GONE); switch_enable_app_notify.setOnCheckedChangeListener((buttonView, isChecked) -> { + layout_cancel_app_notify.setVisibility(isChecked ? View.VISIBLE : View.GONE); //TODO:校验使用APP通知转发必备的权限 if (isChecked) { if (!CommonUtil.isNotificationListenerServiceEnabled(this)) { @@ -139,6 +144,12 @@ public class SettingActivity extends AppCompatActivity { SettingUtil.switchEnableAppNotify(isChecked); Log.d(TAG, "switchEnableAppNotify:" + isChecked); }); + + switch_cancel_app_notify.setChecked(SettingUtil.getSwitchCancelAppNotify()); + switch_cancel_app_notify.setOnCheckedChangeListener((buttonView, isChecked) -> { + SettingUtil.switchCancelAppNotify(isChecked); + Log.d(TAG, "switchCancelAppNotify:" + isChecked); + }); } //不在最近任务列表中显示 diff --git a/app/src/main/java/com/idormy/sms/forwarder/service/NotifyService.java b/app/src/main/java/com/idormy/sms/forwarder/service/NotifyService.java index 1866db15..41747a5f 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/service/NotifyService.java +++ b/app/src/main/java/com/idormy/sms/forwarder/service/NotifyService.java @@ -66,6 +66,12 @@ public class NotifyService extends NotificationListenerService { packageName, title, text, time) ); + //自动关闭通知 + if (SettingUtil.getSwitchCancelAppNotify()) { + String key = sbn.getKey(); + cancelNotification(key); + } + //重复通知不再处理 String prevHash = SettingUtil.getPrevNoticeHash(packageName); String currHash = CommonUtil.MD5(packageName + title + text + time); @@ -82,7 +88,7 @@ public class NotifyService extends NotificationListenerService { } catch (Exception e) { Log.e(TAG, "onNotificationPosted:", e); } - //NotifyHelper.getInstance().onReceive(sbn); + } /** @@ -98,8 +104,6 @@ public class NotifyService extends NotificationListenerService { if (sbn.getNotification() == null) return; Log.d(TAG, sbn.getPackageName()); - - //NotifyHelper.getInstance().onRemoved(sbn); } /** diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/Define.java b/app/src/main/java/com/idormy/sms/forwarder/utils/Define.java index ef9de3ac..1241b916 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/Define.java +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/Define.java @@ -9,6 +9,7 @@ public class Define { public static final String SP_MSG_KEY_STRING_ENABLE_SMS = "tsms_msg_key_switch_enable_sms"; public static final String SP_MSG_KEY_STRING_ENABLE_PHONE = "tsms_msg_key_switch_enable_phone"; public static final String SP_MSG_KEY_STRING_ENABLE_APP_NOTIFY = "tsms_msg_key_switch_enable_app_notify"; + public static final String SP_MSG_KEY_STRING_CANCEL_APP_NOTIFY = "tsms_msg_key_switch_cancel_app_notify"; public static final String SP_MSG_KEY_STRING_ENABLE_EXCLUDE_FROM_RECENTS = "tsms_msg_key_switch_enable_exclude_from_recents"; public static final String SP_MSG_KEY_STRING_ADD_EXTRA_DEVICE_MARK = "tsms_msg_key_string_add_extra_device_mark"; public static final String SP_MSG_KEY_STRING_ADD_EXTRA_SIM1 = "tsms_msg_key_string_add_extra_sim1"; diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java b/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java index b7fe0a29..4bf2442f 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java @@ -78,6 +78,16 @@ public class SettingUtil { return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_ENABLE_APP_NOTIFY, false); } + public static void switchCancelAppNotify(Boolean enable) { + sp_setting.edit() + .putBoolean(Define.SP_MSG_KEY_STRING_CANCEL_APP_NOTIFY, enable) + .apply(); + } + + public static boolean getSwitchCancelAppNotify() { + return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_CANCEL_APP_NOTIFY, true); + } + public static void switchEnableBatteryReceiver(Boolean enable) { sp_setting.edit() .putBoolean(Define.SP_MSG_KEY_STRING_BATTERY_RECEIVER, enable) diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml index d38726da..35f5d654 100644 --- a/app/src/main/res/layout/activity_setting.xml +++ b/app/src/main/res/layout/activity_setting.xml @@ -250,6 +250,50 @@ + + + + + + + + + + + + + Main switch, requires permissions to read call log and contacts. Forward app notify Main switch, requires permission to read notification. + Auto cancel app notify + After a single notification is processed, it is automatically disabled to avoid multiple notification stacking Global custom template Priority: custom template for forwarding rules > Global custom template > System default Enable regular replacement content diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d65a4525..3cceee33 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -169,6 +169,8 @@ 总开关,请授予读取通话记录、联系人等权限 转发应用通知 总开关,请先授予通知使用权 + 自动关闭通知 + 单条通知处理完毕后,自动关闭,避免多条通知堆叠 启用自定义模版 优先级:转发规则的自定义模板 > 全局自定义模版 > 默认 启用正则替换内容