I need to do an application that turn off the mobile screen and go to sleep programmatically. For example if screen is on for more than 5 minutes without user_present, I should turn it off. I tried to use PowerManager (goToSleep() function should do exactly what I want, but it seems not working):
PowerManager pm = (PowerManager) m_context.getSystemService(Context.POWER_SERVICE);
if (pm.isScreenOn() )
{
pm.goToSleep(System.currentTimeMillis() + 1000
}
I have the following permission in my manifest:
<uses-permission android:name="android.permission.DEVICE_POWER"/>
It throws an exception: java.lang.SecurityException: Neither user 10068 nor current process has android.permission.DEVICE_POWER. but I have this permission in my manifest.
Is there another method for doing this, without rooting my phone?