Android 设置默认桌面,默认应用,辅助功能,电池优化,设备管理器,悬浮窗等

Android 设置默认桌面,默认应用,辅助功能,电池优化,设备管理器,悬浮窗等

 

 

Android 部分系统设置桌面,默认应用,辅助功能,电池优化,设备管理器,悬浮窗,有权限查看使用情况,开机自启动,锁屏不清理等
部分功能适配了华为手机与小米手机.

设置默认桌面:

    //华为手机上
    Intent  paramIntent = new Intent("android.intent.action.MAIN");
    paramIntent.setComponent(new ComponentName("com.huawei.android.internal.app", "com.huawei.android.internal.app.HwResolverActivity"));
    paramIntent.addCategory("android.intent.category.DEFAULT");
    paramIntent.addCategory("android.intent.category.HOME");
    startActivity(paramIntent);

    //大部分手机上
    Intent  paramIntent = new Intent("android.intent.action.MAIN");
    paramIntent.setComponent(new ComponentName("android", "com.android.internal.app.ResolverActivity"));
    paramIntent.addCategory("android.intent.category.DEFAULT");
    paramIntent.addCategory("android.intent.category.HOME");
    startActivity(paramIntent);

进入打开辅助功能界面:

    Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
    startActivity(intent);

进入电池优化界面:

    @SuppressLint("BatteryLife") Intent intentBattery = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
    intentBattery.setData(Uri.parse("package:" + getPackageName()));
    startActivity(intentBattery);

进入设置为设备管理器界面:

    ComponentName mComponentName = new ComponentName(getApplicationContext(), PolicyAdmin.class);
    Intent intentDevice = new Intent();
    intentDevice.setAction(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intentDevice.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mComponentName);
    startActivity(intentDevice);

进入有权限查看使用情况的应用界面:

    Intent intentUsage = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
    startActivity(intentUsage);

进入应用开机自启动界面:

Intent intentAutoStart = new Intent();
if (PermissionUtil.checkPhone().equals("HuaWei")) {
    intentAutoStart.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");
    startActivity(intentAutoStart);
} else if (PermissionUtil.checkPhone().equals("XiaoMi")) {
    intentAutoStart.setClassName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity");
    startActivity(intentAutoStart);
} else {
    Toast.makeText(this, "未适配机型", Toast.LENGTH_SHORT).show();
}

进入设置锁屏不清理界面:

if (PermissionUtil.checkPhone().equals("HuaWei")) {
    Intent intentScreenLock = new Intent();
    intentScreenLock.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity");
    startActivity(intentScreenLock);
} else if (PermissionUtil.checkPhone().equals("XiaoMi")) {
    Intent intentScreenLock = new Intent();
    intentScreenLock.setClassName("com.miui.powerkeeper", "com.miui.powerkeeper.ui.HiddenAppsContainerManagementActivity");
    startActivity(intentScreenLock);
} else {
    Toast.makeText(this, "未适配机型", Toast.LENGTH_SHORT).show();
}

进入设置悬浮窗界面:

if (PermissionUtil.checkPhone().equals("HuaWei")) {
    Intent intentSuWindow = new Intent();
    intentSuWindow.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.addviewmonitor.AddViewMonitorActivity");
    startActivity(intentSuWindow);
} else {
    Intent intentSuWindow = new Intent();
    intentSuWindow.setClassName("com.android.settings", "com.android.settings.Settings$OverlaySettingsActivity");
    startActivity(intentSuWindow);
}

进入"在其他应用的上层显示"

   Intent intent2 = new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION");
   startActivity(intent2);

部分华为手机进入通知中心

    Intent intent = new Intent();
    intent.setClassName("com.huawei.systemmanager", "com.huawei.notificationmanager.ui.NotificationManagmentActivity");
    startActivity(intent);

部分华为手机进入权限设置

    Intent intent = new Intent();
    intent.setClassName("com.huawei.systemmanager", "com.huawei.permissionmanager.ui.MainActivity");
    startActivity(intent);

进入设置默认应用界面:

if (PermissionUtil.checkPhone().equals("HuaWei")) {
    Intent hwIntent = new Intent();
    hwIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    hwIntent.setClassName("com.android.settings", "com.android.settings.Settings$PreferredListSettingsActivity");
    startActivity(hwIntent);
} else {
    try {
        Intent launcherIntent = new Intent();
        launcherIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        launcherIntent.setClassName("com.android.settings", "com.android.settings.Settings$HomeSettingsActivity");
        startActivity(launcherIntent);
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(this, "未适配机型", Toast.LENGTH_SHORT).show();
    }
}

 

你可能感兴趣的:(Android)