我曾使用下面的代码锁定设备,并关闭设备屏幕指示灯。
我需要在设备屏幕上轻按一下,即可解锁设备并打开屏幕指示灯。
val policyManager =context.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val adminReceiver = ComponentName(context, KioskAdmin::class.java!!)
val admin = policyManager.isAdminActive(adminReceiver)
if (admin) {
Log.i("TURN_OFF", "Going to sleep now.")
policyManager.lockNow()
}