Question

I'm working on a Home Screen replacement app. I have an activity set as default and I want to override (in a sense) what happens when the Home button is double tapped. So far I have code in the onResume() method of the Home activity that detects if the Home button was tapped twice in quick succession. So essentially, I have code that I can run if the Home button is double tapped.

The problem is that on top of my code, there is an app that the user can set in settings that launches when the Home button is double tapped. So both my code is run AND this app is launched. It seems that there is no way to override the system double tap of the Home button (from what I've read on SO), but is there a way to bring up the chooser dialog wherein the user selects the app to launch upon double tap, and prompt him to select "None"? Or something akin to that where the user is brought to his own Settings and urged to change them?

EDIT: Alternatively, if I CAN override the double tap of the Home Button (something I maybe missed on SO) to do nothing while my activity is running, how can that be done?

Was it helpful?

Solution

The following code, placed on onResume() of a Home Screen replacement activity, allows you to run a block of code when Home is tapped twice in succession. int detectDoubleTap = 0; // Define this either as a static variable in external class or else in the onCreate() and make variable global

if (System.currentTimeMillis() - detectDoubleTap < 250) {
    // Code to be run on double tap
}
detectDoubleTap = System.currentTimeMillis();

While this works fine, it doesn't seem (to answer my question) that there is any way to forcibly override whatever the user has set up as the Double Tap Launch App. So if there is an app that is launched on double tap, the code above will run, AND the app will launch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top