android 系统设置
程序员文章站
2022-04-17 09:47:45
设备亮度设置/** * 获取屏幕亮度模式 * @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
上一篇: 鲁大师怎么跑分 测试电脑性能跑多少分算高
下一篇: Python 打印杨辉三角形