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);
}