mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); //得到最大音量 mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); //得到当前音量 mVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); //改变声音 mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, index, 0);
//得到当前亮度 mBrightness = getWindow().getAttributes().screenBrightness; //调节屏幕亮度 WindowManager.LayoutParams wlp = getWindow().getAttributes(); wlp.screenBrightness = mBrightness + percent; if(wlp.screenBrightness > 1.0f){ wlp.screenBrightness = 1.0f; }else if(wlp.screenBrightness < 0.05f){ wlp.screenBrightness = 0.05f; } getWindow().setAttributes(wlp);