当前位置: 移动技术网 > 移动技术>移动开发>Android > android 系统设置

android 系统设置

2020年08月14日  | 移动技术网移动技术  | 我要评论
设备亮度设置/** * 获取屏幕亮度模式 * @param context */ public static int getScreenBrightMode(Context context) { int mode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL; try { mode = Settings.System.getInt(context.getConte

设备亮度设置

/**
     * 获取屏幕亮度模式
     * @param context
     */
    public static int getScreenBrightMode(Context context) {
        int mode = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
        try {
            mode = Settings.System.getInt(context.getContentResolver(),
                    Settings.System.SCREEN_BRIGHTNESS_MODE);
        } catch (Settings.SettingNotFoundException e) {
            Logs.exception.e("get system screen bright mode exception:" + e);
        }
        return mode;
    }

    /**
     * 设置屏幕亮度模式
     * @param context
     */
    public static void setScreenBrightMode(Context context, int mode) {
        if (mode == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
            Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE,
                    Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
        } else {
            Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE,
                    Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
        }
    }

    /**
     * 获取屏幕亮度
     * @param context
     */
    public static int getScreenBright(Context context) {
        int val = Settings.System.getInt(context.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS, 127);
        return Math.round(val/2.55f);
    }

    /**
     * 设置屏幕亮度
     *
     * @param context
     * @param level
     */
    public static void setScreenBright(Context context, int level) {
        int index = Math.round(level * 2.55f);
        Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS,
                index);
    }

设置按键音

    /**
     * 获取按键音设置
     */
    public static int getKeySoundEffects(Context context) {
        return Settings.System.getInt(context.getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, 0);
    }

    /**
     * 设置按键音设置
     */
    public static void setKeySoundEffects(Context context, int enabled) {
        if (enabled == 0) {
            Settings.System.putInt(context.getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, 0);
        } else {
            Settings.System.putInt(context.getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, 1);
        }
    }
// 自定义按键音
// 自定义控件的按键音设置:
View.playSoundEffect(SoundEffectConstants.CLICK);
// 1、如果想让没有触摸音的控件发音,需要在对应事件中加入上句;
// 2、前提1:系统按键音需打开
// 3、前提2:View的soundEffectsEnabled属性需设为true

本文地址:https://blog.csdn.net/C_Creator/article/details/107942245

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网