3

I noticed that when ever we connect our android device to the charger then the Screen wake up.
So my Question is Is it possible to make an app that restrict the enabling of the screen every time we connect our device to the charger.

I tried this using the code but it seems to be not working

    int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
    boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
    boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;


    if(usbCharge|acCharge)
    {
        turnScreenOFF();
    }
}
private void turnScreenOFF(){
    params = getWindow().getAttributes();
    /** Turn OFF: */
   /* params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
    params.screenBrightness = 0.0f; // 0.1f to turn the brightness to lowest
    getWindow().setAttributes(params);*/
    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.screenBrightness = -1;
    getWindow().setAttributes(params);
}
Ritesh
  • 876
  • 9
  • 14
  • This is an app which does what you're trying to do: https://play.google.com/store/apps/details?id=uk.co.bitsimple.android.solarscreenoff – Kurt Raschke Feb 16 '16 at 23:27
  • Yes But as a developer I am curious to know how can we do this programmatically. – Ritesh Feb 17 '16 at 16:14

0 Answers0