当前位置:   article > 正文

android 设置系统屏幕亮度_android 获取屏幕亮度为-1是什么情况

android 获取屏幕亮度为-1是什么情况

http://www.cnblogs.com/jason-star/archive/2012/10/15/2724494.html



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


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/699928
推荐阅读
相关标签
  

闽ICP备14008679号