Browse Source

1.增加护眼模式调用

master
wangwanlei 8 months ago
parent
commit
236a3a0e7c
1 changed files with 12 additions and 0 deletions
  1. 12
    0
      corelib/src/main/java/com/xhly/corelib/utils/CustomOSUtils.kt

+ 12
- 0
corelib/src/main/java/com/xhly/corelib/utils/CustomOSUtils.kt View File

@@ -5,6 +5,7 @@ import android.content.Context
5 5
 import android.os.Build
6 6
 import androidx.core.content.ContextCompat.getSystemService
7 7
 import java.lang.reflect.Field
8
+import java.lang.reflect.InvocationTargetException
8 9
 import java.lang.reflect.Method
9 10
 
10 11
 class CustomOSUtils {
@@ -65,5 +66,16 @@ class CustomOSUtils {
65 66
             }
66 67
             return null
67 68
         }
69
+        //开启护眼模式
70
+        public fun openOrCloseNightMode(context: Context, open: Boolean) {
71
+            try {
72
+                val cl: Class<*> = Class.forName("android.hardware.display.ColorDisplayManager")
73
+                val control: Any =  context.getSystemService(cl)
74
+                val md: Method = cl.getDeclaredMethod("setNightDisplayActivated", Boolean::class.javaPrimitiveType)
75
+                md.invoke(control, open)
76
+            } catch (e: Exception) {
77
+                LogShow("ClassNotFoundException:" + e.message)
78
+            }
79
+        }
68 80
     }
69 81
 }

Loading…
Cancel
Save