Roses
Roses

Reputation: 59

How to know whether the phone is locked mode?

Is there a way for me to know whether the phone is in locked state?

Upvotes: 3

Views: 2138

Answers (1)

keyboardP
keyboardP

Reputation: 69372

Have your app listen our for the ACTION_SCREEN_OFF broadcast. More information here.

public class ScreenReceiver extends BroadcastReceiver {     

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
                //screen locked                
            } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
                //screen unlocked   
            }
        }

}

You might also want to receive information of when the user gets past the keyguard by registering for the ACTION_USER_PRESENT broadcast.

Upvotes: 1

Related Questions