优化:不在最近任务列表中显示

This commit is contained in:
pppscn 2021-11-21 17:46:11 +08:00
parent aac73b17db
commit 56df57f047
5 changed files with 84 additions and 67 deletions

View File

@ -1,17 +1,16 @@
package com.idormy.sms.forwarder;
import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import com.idormy.sms.forwarder.sender.SendHistory;
import com.idormy.sms.forwarder.service.FrontService;
import com.idormy.sms.forwarder.utils.CommonUtil;
import com.idormy.sms.forwarder.utils.Define;
import com.idormy.sms.forwarder.utils.PhoneUtils;
import com.idormy.sms.forwarder.utils.SettingUtil;
@ -32,39 +31,6 @@ public class MyApplication extends Application {
public static String QyWxAccessToken;
public static long QyWxAccessTokenExpiresIn = 0;
/**
* <meta-data
* android:name="UMENG_CHANNEL"
* android:value="Umeng">
* </meta-data>
*
* @param ctx 上下文
* @return 渠道名称
*/
// 获取渠道工具函数
public static String getChannelName(Context ctx) {
if (ctx == null) {
return null;
}
String channelName = null;
try {
PackageManager packageManager = ctx.getPackageManager();
if (packageManager != null) {
//注意此处为ApplicationInfo 而不是 ActivityInfo,因为友盟设置的meta-data是在application标签中而不是activity标签中所以用ApplicationInfo
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA);
if (applicationInfo.metaData != null) {
channelName = applicationInfo.metaData.get("UMENG_CHANNEL") + "";
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (TextUtils.isEmpty(channelName)) {
channelName = "Unknown";
}
Log.d(TAG, "getChannelName: " + channelName);
return channelName;
}
@Override
protected void attachBaseContext(Context base) {
@ -79,7 +45,7 @@ public class MyApplication extends Application {
try {
//初始化组件化基础库, 所有友盟业务SDK都必须调用此初始化接口
//建议在宿主App的Application.onCreate函数中调用基础组件库初始化函数
UMConfigure.init(this, "60254fc7425ec25f10f4293e", getChannelName(this), UMConfigure.DEVICE_TYPE_PHONE, "");
UMConfigure.init(this, "60254fc7425ec25f10f4293e", CommonUtil.getChannelName(this), UMConfigure.DEVICE_TYPE_PHONE, "");
// 选用LEGACY_AUTO页面采集模式
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.LEGACY_MANUAL);
//pro close log
@ -98,6 +64,16 @@ public class MyApplication extends Application {
SharedPreferences sp = MyApplication.this.getSharedPreferences(Define.SP_CONFIG, Context.MODE_PRIVATE);
showHelpTip = sp.getBoolean(Define.SP_CONFIG_SWITCH_HELP_TIP, true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && SettingUtil.getExcludeFromRecents()) {
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
if (am != null) {
List<ActivityManager.AppTask> appTasks = am.getAppTasks();
if (appTasks != null && !appTasks.isEmpty()) {
appTasks.get(0).setExcludeFromRecents(true);
}
}
}
} catch (Exception e) {
Log.e(TAG, "onCreate:", e);
}

View File

@ -6,8 +6,10 @@ import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationManagerCompat;
@ -25,6 +27,40 @@ public class CommonUtil {
public static final int NOTIFICATION_REQUEST_CODE = 9527;
private static final String ACTION_NOTIFICATION_LISTENER_SETTINGS = "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS";
/**
* <meta-data
* android:name="UMENG_CHANNEL"
* android:value="Umeng">
* </meta-data>
*
* @param ctx 上下文
* @return 渠道名称
*/
// 获取渠道工具函数
public static String getChannelName(Context ctx) {
if (ctx == null) {
return null;
}
String channelName = null;
try {
PackageManager packageManager = ctx.getPackageManager();
if (packageManager != null) {
//注意此处为ApplicationInfo 而不是 ActivityInfo,因为友盟设置的meta-data是在application标签中而不是activity标签中所以用ApplicationInfo
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA);
if (applicationInfo.metaData != null) {
channelName = applicationInfo.metaData.get("UMENG_CHANNEL") + "";
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (TextUtils.isEmpty(channelName)) {
channelName = "Unknown";
}
return channelName;
}
//是否启用通知监听服务
public static boolean isNotificationListenerServiceEnabled(Context context) {
Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages(context);

View File

@ -39,7 +39,7 @@
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="@android:color/white"
@ -48,7 +48,7 @@
android:padding="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -82,7 +82,7 @@
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="@android:color/white"
@ -91,7 +91,7 @@
android:padding="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -125,7 +125,7 @@
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="@android:color/white"
@ -134,7 +134,7 @@
android:padding="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -168,7 +168,7 @@
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="@android:color/white"
@ -177,7 +177,7 @@
android:padding="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -203,7 +203,7 @@
<EditText
android:id="@+id/et_retry_delay_time1"
android:layout_width="42dp"
android:layout_width="40dp"
android:layout_height="48dp"
android:layout_marginStart="5dp"
android:autofillHints=""
@ -216,7 +216,7 @@
<EditText
android:id="@+id/et_retry_delay_time2"
android:layout_width="42dp"
android:layout_width="40dp"
android:layout_height="48dp"
android:layout_marginStart="5dp"
android:autofillHints=""
@ -229,7 +229,7 @@
<EditText
android:id="@+id/et_retry_delay_time3"
android:layout_width="42dp"
android:layout_width="40dp"
android:layout_height="48dp"
android:layout_marginStart="5dp"
android:autofillHints=""
@ -242,7 +242,7 @@
<EditText
android:id="@+id/et_retry_delay_time4"
android:layout_width="42dp"
android:layout_width="40dp"
android:layout_height="48dp"
android:layout_marginStart="5dp"
android:autofillHints=""
@ -255,7 +255,7 @@
<EditText
android:id="@+id/et_retry_delay_time5"
android:layout_width="42dp"
android:layout_width="40dp"
android:layout_height="48dp"
android:layout_marginStart="5dp"
android:autofillHints=""
@ -278,8 +278,9 @@
android:padding="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
<TextView
@ -302,7 +303,7 @@
android:id="@+id/switch_enable_sms"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_weight="1"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
@ -319,8 +320,9 @@
android:padding="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
<TextView
@ -343,7 +345,7 @@
android:id="@+id/switch_enable_phone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_weight="1"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
@ -360,8 +362,9 @@
android:padding="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
<TextView
@ -384,7 +387,7 @@
android:id="@+id/switch_enable_app_notify"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_weight="1"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
@ -401,8 +404,9 @@
android:padding="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
<TextView
@ -425,7 +429,7 @@
android:id="@+id/switch_exclude_from_recents"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_weight="1"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
@ -442,8 +446,9 @@
android:padding="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
<TextView
@ -466,7 +471,7 @@
android:id="@+id/switch_sms_template"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_weight="1"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />

View File

@ -28,12 +28,12 @@
<!-- 选择框自定义主题 -->
<style name="select_style">
<item name="android:layout_width">60dip</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">4dip</item>
<item name="android:layout_marginRight">4dip</item>
<item name="android:paddingTop">4dip</item>
<item name="android:paddingBottom">4dip</item>
<item name="android:layout_marginLeft">5dip</item>
<item name="android:layout_marginRight">5dip</item>
<item name="android:paddingTop">5dip</item>
<item name="android:paddingBottom">5dip</item>
<item name="android:background">@drawable/select_selector</item>
<item name="android:button">@null</item>
<item name="android:gravity">center</item>

View File

@ -153,7 +153,7 @@
<string name="sim1_remark" tools:ignore="Typos">SIM1备注</string>
<string name="sim2_remark" tools:ignore="Typos">SIM2备注</string>
<string name="carrier_mobile">运营商_手机号</string>
<string name="low_power_alarm_threshold">低电量预警阈值</string>
<string name="low_power_alarm_threshold">低电量预警阈值(%)</string>
<string name="low_power_alarm_threshold_tips">取值范围0100留空或0禁用</string>
<string name="retry_interval">每次重试间隔(秒)</string>
<string name="retry_interval_tips">接口请求失败后将重试5次</string>
@ -166,7 +166,7 @@
<string name="forward_app_notify">转发应用通知</string>
<string name="forward_app_notify_tips">总开关,请先授予通知使用权</string>
<string name="enable_custom_templates">启用自定义模版</string>
<string name="enable_custom_templates_tips">全局自定义模版,如果添加转发规则再次定义,则优先取转发规则的</string>
<string name="enable_custom_templates_tips">优先级:转发规则的自定义模板 > 全局自定义模版 > 默认</string>
<string name="enable_exclude_from_recents">不在最近任务列表中显示</string>
<string name="enable_exclude_from_recents_tips">开启后,有效避免手动误杀进程,利于保活?</string>
<string name="custom_templates">转发信息模版</string>