Android 跳转应用设置/热点界面或等常用操作

    //跳转到热点页面
    public static void jumpToHotSpotApPage(Context context) {
        if(!Build.BRAND.equalsIgnoreCase("huawei") && !Build.BRAND.equalsIgnoreCase("honor")){
            jumpToHotSpotApPageCompat(context);
            return;
        }//end of if
        try {
            Intent intent = new Intent();
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.setAction("android.intent.action.MAIN");
            intent.setComponent(new ComponentName("com.android.settings","com.android.settings.Settings$WirelessSettingsActivity"));
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
            jumpToHotSpotApPageCompat(context);
        }
    }

    //跳转到热点页面兼容特殊机型的特殊处理
    public static void jumpToHotSpotApPageCompat(Context context) {
        try {
            Intent intent = new Intent();
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.setAction("android.intent.action.MAIN");
            intent.setComponent(new ComponentName("com.android.settings","com.android.settings.TetherSettings"));
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                Intent intent = new Intent();
                intent.addCategory(Intent.CATEGORY_DEFAULT);
                intent.setAction("android.intent.action.MAIN");
                intent.setComponent(new ComponentName("com.android.settings","com.android.settings.Settings$TetherSettingsActivity"));
                context.startActivity(intent);
            } catch (Exception e2) {
                e2.printStackTrace();
                Utils.Companion.toastMsg("跳转热点界面失败,请手动去打开", true, null);
            }
        }
    }

    //跳转到app设置详情界面
    public static void jumpToAppDetailPage(Context context) {
        try {
            Intent intent = new Intent();
            intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.setData(Uri.parse("package:" + context.getPackageName()));
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
            Utils.Companion.toastMsg("跳转设置界面失败,请手动去打开", true, null);
        }
    }

    //跳转到定位开关页面
    public static void jumpToLocationPage(Context context) {
        try {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
            Utils.Companion.toastMsg("跳转定位开关界面失败,请手动去打开", true, null);
        }
    }

    //判定是否是miui
    public static boolean isMiui() {
        return !TextUtils.isEmpty(Utils.getSystemProperty("ro.miui.ui.version.name"));
    }

    //判定miui是否关闭
    @SuppressLint("PrivateApi")
    public static boolean isMiuiOptimizationDisabled() {
        String miuiOpt = getSystemProperty("persist.sys.miui_optimization");//从未操作过miui开关的时候是空
        if (!TextUtils.isEmpty(miuiOpt) && ("0".equals(miuiOpt) || !"true".equals(miuiOpt))) return true;
        try {
            return (boolean) Class.forName("android.miui.AppOpsUtils")
                    .getDeclaredMethod("isXOptMode")
                    .invoke(null);
        } catch (Exception e) {
            return false;
        }
    }

你可能感兴趣的:(Android 跳转应用设置/热点界面或等常用操作)