前言
有时候,为了确保APP的后台正常运行,需要让用户去设置打开APP的自启动权限(或者改为手动管理/huawei)。为了更好的用户体验,在APP中可以直接跳转到手机的自启动管理页面或者权限管理页面。
应用启动管理页面
oppo/vivo是没有这个页面的
- 华为
ComponentName componentName = null;
int sdkVersion = Build.VERSION.SDK_INT;
try {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//跳自启动管理
if (sdkVersion >= 28){
//9:已测试
componentName = ComponentName.unflattenFromString("com.huawei.systemmanager/.startupmgr.ui.StartupNormalAppListActivity");//跳自启动管理
}else if (sdkVersion >= 26){
//8:已测试
componentName = ComponentName.unflattenFromString("com.huawei.systemmanager/.appcontrol.activity.StartupAppControlActivity");
}else if (sdkVersion >= 23){
//7.6:已测试
componentName = ComponentName.unflattenFromString("com.huawei.systemmanager/.startupmgr.ui.StartupNormalAppListActivity");
}else if (sdkVersion >= 21){
//5
componentName = ComponentName.unflattenFromString("com.huawei.systemmanager/com.huawei.permissionmanager.ui.MainActivity");
}
//componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity");//锁屏清理
intent.setComponent(componentName);
startActivity(intent);
}catch (Exception e){
//跳转失败
}
- 小米
Intent intent = new Intent();
try {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName componentName = null;
componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity");
intent.setComponent(componentName)