1、要实现灭屏和唤醒,需要在Manifest文件添加如下权限:
<!-- 屏幕唤醒 -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- 屏幕熄灭 -->
<user-permission android:name="android.permission.DEVICE_POWER" />
2、以下是封装的一个工具类,实现屏幕唤醒和熄灭
package testWakeAndLock;
import android.content.Context;
import android.os.PowerManager;
import android.os.SystemClock;
import com.example.testshellcmd.SharedApplication;
public class WakeAndLock {
Context context;
PowerManager pm;
PowerManager.WakeLock wakeLock;
public WakeAndLock() {
context = SharedApplication.context;
pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.SCREEN_DIM_WAKE_LOCK, "WakeAndLock");
}
/**
* 唤醒屏幕
*/
p