关闭屏幕、打开屏幕

关闭屏幕

var pm = getSystemService(Context.POWER_SERVICE) as PowerManager
// ReflectUtils.reflect(pm).method("goToSleep",pm, SystemClock.uptimeMillis())
//   powerManager.getClass().getMethod("wakeUp", arrayOf<Class<*>>(Long::class.javaPrimitiveType)).invoke(powerManager, SystemClock.uptimeMillis())
try {
    pm.javaClass.getMethod("goToSleep", Long::class.java)
        .invoke(pm, SystemClock.uptimeMillis())
} catch (e: Exception) {
    XLog.e(e.toString())
}

打开屏幕

var pm = getSystemService(Context.POWER_SERVICE) as PowerManager
                try {
                    pm.javaClass.getMethod("wakeUp", Long::class.java)
                        .invoke(pm, SystemClock.uptimeMillis())
                } catch (e: Exception) {
                    XLog.e(e.toString())
                }
updatedupdated2021-10-222021-10-22