I want the application to pass the device to standby as when pressing the on / off key, but I can not find how to do it.
I want the application to pass the device to standby as when pressing the on / off key, but I can not find how to do it.
This can not be done by any application, it must be a system application so that it has access to be able to perform the action of sending the device to Standby.
For this you can use the class PowerManager but for this you need permission:
<uses-permission android:name="android.permission.DEVICE_POWER"/>
which is only allowed for system applications.
With this method you would achieve what you want:
private void toStandBy(){
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Standby");
wl.acquire();
wl.release();
}