简体   繁体   English

Android 检测 Chromebook 上的锁定解锁事件

[英]Android detect lock Unlock event on Chromebook

I want to detect the Chromebook lock, Unlock event.我想检测 Chromebook 锁定、解锁事件。 I am using Foreground service and register Broadcast to detect Intent.ACTION_SCREEN_ON, Intent.ACTION_SCREEN_OFF, Intent.ACTION_USER_PRESENT.我正在使用前台服务并注册广播来检测 Intent.ACTION_SCREEN_ON、Intent.ACTION_SCREEN_OFF、Intent.ACTION_USER_PRESENT。 Only getting Intent.ACTION_SCREEN_ON, Intent.ACTION_SCREEN_OFF broadcast but not getting Intent.ACTION_USER_PRESENT broadcast on Chromebook.仅获得 Intent.ACTION_SCREEN_ON、Intent.ACTION_SCREEN_OFF 广播但未在 Chromebook 上获得 Intent.ACTION_USER_PRESENT 广播。

override fun onCreate() {
        super.onCreate()
        startForeground()

        intentFilter = IntentFilter(Intent.ACTION_SCREEN_ON)
        intentFilter = IntentFilter(Intent.ACTION_USER_PRESENT)
        intentFilter.addAction(Intent.ACTION_SCREEN_OFF)


       //other code

    }

class XYZBroadcastReceiver : BroadcastReceiver() {


    override fun onReceive(context: Context?, intent: Intent) {

        val action = intent.action

      
        if (Intent.ACTION_USER_PRESENT == action) {
        
        } 
        else if (Intent.ACTION_SCREEN_OFF == action) {
            
        }

        else if(Intent.ACTION_SCREEN_ON == action){
            
        }
    }

I am trying lots of methods from Android detect phone lock event , A way to get unlock event in android?我正在尝试Android 中的很多方法检测电话锁定事件一种在 android 中获取解锁事件的方法? , Android - detect phone unlock event, not screen on but nothing works for Chromebook. , Android - 检测手机解锁事件,不是屏幕开启,但对 Chromebook 没有任何作用。 Is there any other way to detect lock, Unlock events on Android Chromebook?有没有其他方法可以检测 Android Chromebook 上的锁定、解锁事件?

The information you're referring to may be outdated...您所指的信息可能已过时...

Since API level 26 you won't receive this implicit broadcast on regular Android either:由于 API 级别 26,您将不会在常规 Android 上收到此隐式广播:

https://developer.android.com/guide/components/broadcast-exceptions https://developer.android.com/guide/components/broadcast-exceptions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM