I created a new project with target API 15 (ICS) with empty Activity. I added permission to manifest:
<uses-permission android:name="android.permission.WAKE_LOCK" />
I added code to onCreate()
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PowerManager pm = (PowerManager) getSystemService(getApplicationContext().POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Tag");
wl.acquire();
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;
getWindow().setAttributes(params);
}
But nothing happens with the device. According to PowerManager documentation I expected the screen to go off (immediately). So, am I doing something wrong or is this not working?
EDIT:
I tried Ashish Ranjan's suggestion to manually set screenBrightness
after acquiring WakeLock but this too does not work.