|
@@ -8,9 +8,13 @@ import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
+import android.os.PowerManager;
|
|
|
+import android.os.SystemClock;
|
|
|
import android.provider.Settings;
|
|
|
import android.util.Log;
|
|
|
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
+
|
|
|
/**
|
|
|
* Created by asus on 2016/12/8.
|
|
|
* 屏幕亮度调节器
|
|
@@ -115,4 +119,41 @@ public class ScreenManagerUtil {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关闭屏幕 ,其实是使系统休眠
|
|
|
+ */
|
|
|
+ public static void goToSleep(Context context) {
|
|
|
+ PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
|
+ try {
|
|
|
+ powerManager.getClass().getMethod("goToSleep", new Class[]{long.class}).invoke(powerManager, SystemClock.uptimeMillis());
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (NoSuchMethodException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 唤醒屏幕
|
|
|
+ *
|
|
|
+ * @param context
|
|
|
+ */
|
|
|
+ public static void wakeUp(Context context) {
|
|
|
+ PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
|
+ try {
|
|
|
+ powerManager.getClass().getMethod("wakeUp", new Class[]{long.class}).invoke(powerManager, SystemClock.uptimeMillis());
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (NoSuchMethodException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|