一、休眠
public boolean goToSleep() {
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
try {
Method method = pm.getClass().getMethod("goToSleep", Long.TYPE);
method.invoke(pm, SystemClock.uptimeMillis());
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
二、关屏
DevicePolicyManager devicePolicyManager = (DevicePolicyManager)
getSystemService(Context.DEVICE_POLICY_SERVICE);
devicePolicyManager.lockNow();
三、亮屏
DevicePolicyManager devicePolicyManager = (DevicePolicyManager)
getSystemService(Context.DEVICE_POLICY_SERVICE);
devicePolicyManager.resetPassword(null, 0);
注:权限
<uses-permission android:name="android.permission.DEVICE_POWER" />
android:sharedUserId="android.uid.system"//并使用系统签名