|
@@ -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
|
}
|