I'm trying to create an app and I'm nearly complete. I have been trying to figure out how to either put the phone into sleep mode, which would also lock the screen or just lock the screen.
This is how I am currently trying to accomplish this using the PowerManager.
try{
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "FACEDOWN_LOCK");
wl.acquire();
// ? Perform operations
pm.goToSleep(SystemClock.uptimeMillis());
wl.release();
}catch(Exception e){
Toast.makeText(this, e.getMessage() , 10000).show();
}
This does NOT work. It gives me permission problems even though my app is signed and I have the permissions enabled in the manifest.xml
<permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="android.permission.DEVICE_POWER" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
Is there a proper way to do this? Can it even be done? Any help would be awesome. I have not been able to find any solution as to how you get the phone to lock or go to sleep.