Search code examples
androidvolumebrightness

Control Android Brightness and Volume at Set Time


I am trying to create an Android app that will change the volume and brightness of the user's device at a time either set by the user, or hard coded into the app itself.

I have searched on StackOverflow, but the closest I have got to is setting the brightness only in the app. I want the app to set the brightness and volume permanently across the entire device until the set time passes. Any idea how I can do this?


Solution

  • You can find the methods that you are looking for on the android developer documentation.

    Setting Volume: The AdjustVolume(int,int) method should be what you are looking for. http://developer.android.com/reference/android/media/AudioManager.html#adjustVolume(int,%20int)

    Settings Brightness:

    private void setBrightness(int brightness) {
        try {
          IHardwareService hardware = IHardwareService.Stub.asInterface(
    ServiceManager.getService("hardware"));
          if (hardware != null) {
            hardware.setScreenBacklight(brightness);
          }
        } catch (RemoteException doe) {          
        }        
      }
    

    https://web.archive.org/web/20210224163252/http://www.tutorialforandroid.com/2009/01/changing-screen-brightness.html