mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 01:17:41 +08:00
新增:允许开启自动关闭通知(单条通知处理完毕后自动关闭,避免多条通知堆叠)
This commit is contained in:
parent
88768342c2
commit
edb39867c1
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
//不在最近任务列表中显示
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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";
|
||||
|
@ -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)
|
||||
|
@ -250,6 +250,50 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_cancel_app_notify"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:background="@android:color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="15dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="4"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/cancel_app_notify"
|
||||
android:textStyle="bold"
|
||||
tools:ignore="RelativeOverlap" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:text="@string/cancel_app_notify_tips"
|
||||
android:textSize="9sp"
|
||||
tools:ignore="SmallSp" />
|
||||
</LinearLayout>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switch_cancel_app_notify"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="end"
|
||||
android:textSize="18sp"
|
||||
tools:ignore="UseSwitchCompatOrMaterialXml" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -169,6 +169,8 @@
|
||||
<string name="forward_missed_calls_tips">Main switch, requires permissions to read call log and contacts.</string>
|
||||
<string name="forward_app_notify">Forward app notify</string>
|
||||
<string name="forward_app_notify_tips">Main switch, requires permission to read notification.</string>
|
||||
<string name="cancel_app_notify">Auto cancel app notify</string>
|
||||
<string name="cancel_app_notify_tips">After a single notification is processed, it is automatically disabled to avoid multiple notification stacking</string>
|
||||
<string name="enable_custom_templates">Global custom template</string>
|
||||
<string name="enable_custom_templates_tips">Priority: custom template for forwarding rules > Global custom template > System default</string>
|
||||
<string name="enable_regex_replace">Enable regular replacement content</string>
|
||||
|
@ -169,6 +169,8 @@
|
||||
<string name="forward_missed_calls_tips">总开关,请授予读取通话记录、联系人等权限</string>
|
||||
<string name="forward_app_notify">转发应用通知</string>
|
||||
<string name="forward_app_notify_tips">总开关,请先授予通知使用权</string>
|
||||
<string name="cancel_app_notify">自动关闭通知</string>
|
||||
<string name="cancel_app_notify_tips">单条通知处理完毕后,自动关闭,避免多条通知堆叠</string>
|
||||
<string name="enable_custom_templates">启用自定义模版</string>
|
||||
<string name="enable_custom_templates_tips">优先级:转发规则的自定义模板 > 全局自定义模版 > 默认</string>
|
||||
<string name="enable_regex_replace">启用正则替换内容</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user