2

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?

Deqing
  • 14,098
  • 15
  • 84
  • 131

1 Answers1

1

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

Community
  • 1
  • 1
AmmarCSE
  • 30,079
  • 5
  • 45
  • 53