in an android app, turn screen off when user touch a button.
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;
This code makes screen dim, but can't turn off.
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
//..screen will stay on during this section..
This code keep a phone at 'Wake_State'. In following Table,
'PARTIAL_WAKE_LOCK' looks to turn off screen. But it just allows that a user turn screen off personally (maybe with power-button).
You can achieve it by setting the wake_setting time to 1 second.
I have already tried both of above shared ways, which shows slightly visible screen on but by setting wake_setting to 1 sec.
I have to just turn off the screen. For that purpose you are going to add SETTING_Change permission ( only available in rooted handset).