近期項(xiàng)目中需要設(shè)置應(yīng)用自啟動(dòng),保留后臺(tái)等功能自点,多方查找遂赠,最后發(fā)現(xiàn)并總結(jié)了以下這個(gè)工具類
特別感謝這個(gè)博主久妆,提供了思路,同時(shí)也提供了代碼
原文鏈接 https://blog.csdn.net/u014418171/article/details/98874962/
獲取當(dāng)前頁面adb命令
adb shell dumpsys window | grep mCurrentFocus
具體代碼
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 跳轉(zhuǎn)自啟動(dòng)頁面解決方案
*
* @author zhj
*/
public class Util {
private static HashMap<String, List<String>> hashMap = new HashMap<String, List<String>>() {
{
put("Xiaomi", Arrays.asList(
"com.miui.securitycenter/com.miui.permcenter.autostart.AutoStartManagementActivity",
"com.miui.securitycenter"
));
put("samsung", Arrays.asList(
"com.samsung.android.sm_cn/com.samsung.android.sm.ui.ram.AutoRunActivity",
"com.samsung.android.sm_cn/com.samsung.android.sm.ui.appmanagement.AppManagementActivity",
"com.samsung.android.sm_cn/com.samsung.android.sm.ui.cstyleboard.SmartManagerDashBoardActivity",
"com.samsung.android.sm_cn/.ui.ram.RamActivity",
"com.samsung.android.sm_cn/.app.dashboard.SmartManagerDashBoardActivity",
"com.samsung.android.sm/com.samsung.android.sm.ui.ram.AutoRunActivity",
"com.samsung.android.sm/com.samsung.android.sm.ui.appmanagement.AppManagementActivity",
"com.samsung.android.sm/com.samsung.android.sm.ui.cstyleboard.SmartManagerDashBoardActivity",
"com.samsung.android.sm/.ui.ram.RamActivity",
"com.samsung.android.sm/.app.dashboard.SmartManagerDashBoardActivity",
"com.samsung.android.lool/com.samsung.android.sm.ui.battery.BatteryActivity",
"com.samsung.android.sm_cn",
"com.samsung.android.sm"
));
put("HUAWEI", Arrays.asList(
"com.huawei.systemmanager/.startupmgr.ui.StartupNormalAppListActivity",
"com.huawei.systemmanager/.appcontrol.activity.StartupAppControlActivity",
"com.huawei.systemmanager/.optimize.process.ProtectActivity",
"com.huawei.systemmanager/.optimize.bootstart.BootStartActivity",
"com.huawei.systemmanager"
));
put("vivo", Arrays.asList(
"com.iqoo.secure/.ui.phoneoptimize.BgStartUpManager",
"com.iqoo.secure/.safeguard.PurviewTabActivity",
"com.vivo.permissionmanager/.activity.BgStartUpManagerActivity",
// "com.iqoo.secure/.ui.phoneoptimize.AddWhiteListActivity", //這是白名單, 不是自啟動(dòng)
"com.iqoo.secure",
"com.vivo.permissionmanager"
));
put("Meizu", Arrays.asList(
"com.meizu.safe/.permission.SmartBGActivity",
"com.meizu.safe/.permission.PermissionMainActivity",
"com.meizu.safe"
));
put("OPPO", Arrays.asList(
"com.coloros.safecenter/.startupapp.StartupAppListActivity",
"com.coloros.safecenter/.permission.startup.StartupAppListActivity",
"com.oppo.safe/.permission.startup.StartupAppListActivity",
"com.coloros.oppoguardelf/com.coloros.powermanager.fuelgaue.PowerUsageModelActivity",
"com.coloros.safecenter/com.coloros.privacypermissionsentry.PermissionTopActivity",
"com.coloros.safecenter",
"com.oppo.safe",
"com.coloros.oppoguardelf"
));
put("oneplus", Arrays.asList(
"com.oneplus.security/.chainlaunch.view.ChainLaunchAppListActivity",
"com.oneplus.security"
));
put("letv", Arrays.asList(
"com.letv.android.letvsafe/.AutobootManageActivity",
"com.letv.android.letvsafe/.BackgroundAppManageActivity",
"com.letv.android.letvsafe"
));
put("zte", Arrays.asList(
"com.zte.heartyservice/.autorun.AppAutoRunManager",
"com.zte.heartyservice"
));
//金立
put("F", Arrays.asList(
"com.gionee.softmanager/.MainActivity",
"com.gionee.softmanager"
));
//以下為未確定(廠商名也不確定)
put("smartisanos", Arrays.asList(
"com.smartisanos.security/.invokeHistory.InvokeHistoryActivity",
"com.smartisanos.security"
));
//360
put("360", Arrays.asList(
"com.yulong.android.coolsafe/.ui.activity.autorun.AutoRunListActivity",
"com.yulong.android.coolsafe"
));
//360
put("ulong", Arrays.asList(
"com.yulong.android.coolsafe/.ui.activity.autorun.AutoRunListActivity",
"com.yulong.android.coolsafe"
));
//酷派
put("coolpad"/*廠商名稱不確定是否正確*/, Arrays.asList(
"com.yulong.android.security/com.yulong.android.seccenter.tabbarmain",
"com.yulong.android.security"
));
//聯(lián)想
put("lenovo"/*廠商名稱不確定是否正確*/, Arrays.asList(
"com.lenovo.security/.purebackground.PureBackgroundActivity",
"com.lenovo.security"
));
put("htc"/*廠商名稱不確定是否正確*/, Arrays.asList(
"com.htc.pitroad/.landingpage.activity.LandingPageActivity",
"com.htc.pitroad"
));
//華碩
put("asus"/*廠商名稱不確定是否正確*/, Arrays.asList(
"com.asus.mobilemanager/.MainActivity",
"com.asus.mobilemanager"
));
//酷派
put("YuLong", Arrays.asList(
"com.yulong.android.softmanager/.SpeedupActivity",
"com.yulong.android.security/com.yulong.android.seccenter.tabbarmain",
"com.yulong.android.security"
));
// 榮耀 實(shí)測(cè)機(jī)型(HONOR 50 SE)
put("HONOR", Arrays.asList(
"com.hihonor.systemmanager/com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity",
"com.hihonor.systemmanager"
));
}
};
public static void startToAutoStartSetting(Context context) {
Log.e("Util", "******************當(dāng)前手機(jī)型號(hào)為:" + Build.MANUFACTURER);
Set<Map.Entry<String, List<String>>> entries = hashMap.entrySet();
for (Map.Entry<String, List<String>> entry : entries) {
String manufacturer = entry.getKey();
List<String> actCompatList = entry.getValue();
if (Build.MANUFACTURER.equalsIgnoreCase(manufacturer)) {
for (String act : actCompatList) {
try {
Intent intent;
if (act.contains("/")) {
intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName componentName = ComponentName.unflattenFromString(act);
intent.setComponent(componentName);
} else {
//所以我是直接跳轉(zhuǎn)到對(duì)應(yīng)的安全管家/安全中心
intent = context.getPackageManager().getLaunchIntentForPackage(act);
}
context.startActivity(intent);
break;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}