Screen brightness adjustment
/** * Swipe to change brightness, do not require permission * * @param percent brightness percentage, value is 0.0----1.0 */private void Onbrightnessslide (float percent) {if (mbrightn ESS < 0) {//mbrightness is the brightness of the current screen mbrightness = GetWindow (). GetAttributes (). screenbrightness; if (mbrightness <= 0.00f) mbrightness = 0.50f; if (Mbrightness < 0.01f) mbrightness = 0.01f; Display Moperationbg.setimageresource (R.DRAWABLE.VIDEO_BRIGHTNESS_BG); Mvolumebrightnesslayout.setvisibility (view.visible); } windowmanager.layoutparams LPA = GetWindow (). GetAttributes (); Lpa.screenbrightness = mbrightness + percent; if (lpa.screenbrightness > 1.0f) lpa.screenbrightness = 1.0f; else if (Lpa.screenbrightness < 0.01f) lpa.screenbrightness = 0.01f; GetWindow (). SetAttributes (LPA); Viewgroup.layoutparams LP = Moperationpercent.getlayoutparams (); This section is a lp.width = (int) (Findviewbyid (R.id.operation_full)) that changes the progress of the current brightness above the picture. Getlayoutparams (). Width * Lpa.screenbrightness); MOPERATIONPERCENT.SETLAYOUTPARAMS (LP);}
Volume adjustment
/** * Volume adjustment, do not need permission */public class Mainactivity extends Activity {private static final String TAG = "mainactivity"; Private Audiomanager Maudiomanager; private int currentvolume; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Maudiomanager = (Audiomanager) getsystemservice (Audio_service); Maximum volume int maxvolume = Maudiomanager. Getstreammaxvolume (Audiomanager.stream_music); LOG.I (TAG, "Maximum Volume:" + Maxvolume); Currentvolume = Maudiomanager. Getstreamvolume (Audiomanager.stream_music); LOG.I (TAG, "Current Volume:" + Currentvolume); public void up (view view) {///volume increased//Audiomanager.stream_system Maudiomanager.adjuststreamvolu Me (Audiomanager.stream_music, audiomanager.adjust_raise, audiomanager.fx_focus_navigation_up); Currentvolume = Maudiomanager.Getstreamvolume (Audiomanager.stream_music); LOG.I (TAG, "Current Volume:" + Currentvolume); public void-down (view view) {///volume decrease Maudiomanager.adjuststreamvolume (Audiomanager.stream_music, Audiomanager.adjust_lower, AUDIOMANAGER.FX_FOCUS_NAVIGATION_UP); Currentvolume = Maudiomanager. Getstreamvolume (Audiomanager.stream_music); LOG.I (TAG, "Current Volume:" + Currentvolume); }}
Welcome Androider Scan The following two-dimensional code attention to the public number: Ayandio, or search: loveandroid321 attention
"Android" system volume and screen brightness adjustment