android 设置系统屏幕亮度

转至:http://daikainan.iteye.com/blog/1455323


这样调用即可达到屏幕最亮

getScreenMode();
getScreenBrightness();
setScreenMode(0);
saveScreenBrightness(255);
setScreenBrightness(255);

  1. /** 
  2.      * 获得当前屏幕亮度的模式     
  3.      * SCREEN_BRIGHTNESS_MODE_AUTOMATIC=1 为自动调节屏幕亮度 
  4.      * SCREEN_BRIGHTNESS_MODE_MANUAL=0  为手动调节屏幕亮度 
  5.      */  
  6.       private int getScreenMode(){  
  7.         int screenMode=0;  
  8.         try{  
  9.             screenMode = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);  
  10.         }  
  11.         catch (Exception localException){  
  12.               
  13.         }  
  14.         return screenMode;  
  15.       }  
  16.         
  17.      /** 
  18.      * 获得当前屏幕亮度值  0--255 
  19.      */  
  20.       private int getScreenBrightness(){  
  21.         int screenBrightness=255;  
  22.         try{  
  23.             screenBrightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);  
  24.         }  
  25.         catch (Exception localException){  
  26.             
  27.         }  
  28.         return screenBrightness;  
  29.       }  
  30.     /** 
  31.      * 设置当前屏幕亮度的模式     
  32.      * SCREEN_BRIGHTNESS_MODE_AUTOMATIC=1 为自动调节屏幕亮度 
  33.      * SCREEN_BRIGHTNESS_MODE_MANUAL=0  为手动调节屏幕亮度 
  34.      */  
  35.       private void setScreenMode(int paramInt){  
  36.         try{  
  37.           Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, paramInt);  
  38.         }catch (Exception localException){  
  39.           localException.printStackTrace();  
  40.         }  
  41.       }  
  42.       /** 
  43.        * 设置当前屏幕亮度值  0--255 
  44.        */  
  45.       private void saveScreenBrightness(int paramInt){  
  46.         try{  
  47.           Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, paramInt);  
  48.         }  
  49.         catch (Exception localException){  
  50.           localException.printStackTrace();  
  51.         }  
  52.       }  
  53.       /** 
  54.        * 保存当前的屏幕亮度值,并使之生效 
  55.        */  
  56.       private void setScreenBrightness(int paramInt){  
  57.         Window localWindow = getWindow();  
  58.         WindowManager.LayoutParams localLayoutParams = localWindow.getAttributes();  
  59.         float f = paramInt / 255.0F;  
  60.         localLayoutParams.screenBrightness = f;  
  61.         localWindow.setAttributes(localLayoutParams);  
  62.       }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值