更新时间:2022-04-28 01:12:13
让您的应用收听我们的 ACTION_SCREEN_OFF
广播.详细信息此处.
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
}
}
}
您可能还想通过注册 ACTION_USER_PRESENT 广播.
You might also want to receive information of when the user gets past the keyguard by registering for the ACTION_USER_PRESENT broadcast.