3

有没有办法让我知道手机是否处于锁定状态?

4

1 回答 1

1

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.

于 2011-05-15T21:12:48.730 回答