最近在做后台服务常驻业务, 需要APP添加自启白名单功能. 参考了网上的一些资料, 做了一个跳转各厂商自启白名单设置界面帮助类:
有需要的朋友可以参考下.
如下:
/**
* Created by tgvincent on 2018/6/25.
* 国内手机厂商白名单跳转工具类
*
* @author tgvincent
* @version 1.0
*/
public class UWhiteListSetting {
public static void enterWhiteListSetting(Context context) {
try {
context.startActivity(getSettingIntent());
} catch (Exception e) {
context.startActivity(new Intent(Settings.ACTION_SETTINGS));
}
}
private static Intent getSettingIntent() {
ComponentName componentName = null;
String brand = android.os.Build.BRAND;
switch (brand.toLowerCase()) {
case "samsung":
componentName = new ComponentName("com.samsung.android.sm",
"com.samsung.android.sm.app.dashboard.SmartManagerDashBoardActivity");
break;
case "huawei":
componentName = new ComponentName("com.huawei.systemmanager",
"com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");
break;
case "xiaomi":
componentName = new ComponentName("com.miui.securitycenter",
"com.miui.permcenter.autostart.AutoStartManagementActivity");
break;
case "vivo":
componentName = new ComponentName("com.iqoo.secure",
"com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity");
break;
case "oppo":
componentName = new ComponentName("com.coloros.oppoguardelf",
"com.coloros.powermanager.fuelgaue.PowerUsageModelActivity");
break;
case "360":
componentName = new ComponentName("com.yulong.android.coolsafe",
"com.yulong.android.coolsafe.ui.activity.autorun.AutoRunListActivity");
break;
case "meizu":
componentName = new ComponentName("com.meizu.safe",
"com.meizu.safe.permission.SmartBGActivity");
break;
case "oneplus":
componentName = new ComponentName("com.oneplus.security",
"com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity");
break;
default:
break;
}
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (componentName != null) {
intent.setComponent(componentName);
} else {
intent.setAction(Settings.ACTION_SETTINGS);
}
return intent;
}
}
PS:
Android目前没有提供判断APP是否加入到自启白名单的方法. 使用adb命令获取也无效. 所以, 建议添加UI界面, 给用户友好提醒: 如使用某某功能模块需要自启功能, 然后给出快捷跳转设置的UI. 使用上述帮助类, 跳转到相应自启白名单管理界面.