Android home key disable? block question.

Asked 2 years ago, Updated 2 years ago, 66 views

If one activity is carried out, I want to prevent homekey event.

First, we found ways to detect home key events using the onUserLeaveHint method and how to detect them by broadcast.

First, the onUserLeaveHint method was implemented by terminating the activity and calling it again, and the activity is turned on again after 5 seconds. I looked up the reason and they said, "Android 5 second rule?" The onUserLeaveHint method was not implemented when another application was turned on in 5 seconds.


    protected void onUserLeaveHint() {

        //Detect here
        Log.d("gg", "Home Button Touch");
        finish();

        Intent intent = new Intent(this, ShowActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        super.onUserLeaveHint();
    }


The code implemented by the broadcast receiver is http://stackoverflow.com/questions/8881951/detect-home-button-press-in-android I saw it here, but there was no way to stop it.

Lockdown apps are implementing this function, so there must be a way, but it's not coming out

android homekey

2022-09-21 16:20

1 Answers

There is no API to block the home key (although it's a bit old). We can't avoid the five-second delay you mentioned. Most locking apps use two methods:

In addition, after installing famous lock screen apps, run them one by one and see how they are implemented with the activity dump of adb. This will also require learning, but once you get used to it, you can get a hint about how you implemented it.


2022-09-21 16:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.