Reputation: 14632
When user press a button, I would like to set a timer and turn off the screen immediately.
Had searched but looks like it requires DEVICE_POWER
permission, which only available for system app.
Is it possible for a normal app to do this?
Upvotes: 2
Views: 1157
Reputation: 30557
Try
<uses-permission android:name="android.permission.WAKE_LOCK" />
and
PowerManager.WakeLock acquire()
So something like
int field = PowerManager.class.getClass().getField("PROXIMITY_SCREEN_OFF_WAKE_LOCK").getInt(null);
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(field, getLocalClassName());
wakeLock.acquire();
Check out acquire and Turn off screen programmatically when face is close the screen on Android
Upvotes: 1