问题
I need to turn the screen off and on like when you are doing a call and holding the phone to your ear. The screen then turns off but it isn't locked or anything, it's just black.
What is the best way to do that? I don't want to show a black fullscreen activity if there is another solution...:)
回答1:
There are two methods for doing that,
PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
// method 1
manager.goToSleep(int amountOfTime);
// method 2
PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Your Tag");
wl.acquire();// It will swith off
wl.release(); // And swith on
also add this permission,
<uses-permission android:name="android.permission.WAKE_LOCK" />
来源:https://stackoverflow.com/questions/17344359/android-turn-screen-on-and-off-without-locking