How to detect screen lock?

Hi

How can we detect the event when user locks screen while your app is still running / visible?

Regards
Anil

you can use the block App On Pause/Stop event

This isn’t possible using those blocks.

1 Like
1 Like

Correct, app stop does not work when screen is locked

I feel that there is no use if the screen is locked or not locked but instead we can consider whether the app is paused or stopped

1 Like
public boolean IsPhoneLocked(){
        KeyguardManager KM = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
        if( KM.isKeyguardLocked()) {
            return true;
        } else {
            return false;
        }
    }

I think this would work if you made an extension by this code.

will never work because if it is locked app cant even run so if the application is open then it will always return false

I am very new to Kodular btw.
Cant we run the app in background??

nope only using a paid extension

1 Like