Monday, 5 April 2021

Android detect lock Unlock event on Chromebook

I want to detect the Chromebook lock, Unlock event. I am using Foreground service and register Broadcast to detect 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.

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 - detect phone unlock event, not screen on but nothing works for Chromebook. Is there any other way to detect lock, Unlock events on Android Chromebook?



from Android detect lock Unlock event on Chromebook

No comments:

Post a Comment