overriding the Home Key Long press in a category.HOME activity
Asked Answered
R

3

9

I just created my own "Home" to replace the stock android one or Sense.

All is working fine and I get all I want. My only problem is to replace to long press on home key ( that usually show the last 6 activities you launched) by my own launcher.

I successfully replace the long press on MENU button with this code:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

//Log.i(TAG,"Keycode: "+keyCode);

if (keyCode == KeyEvent.KEYCODE_MENU) {
    // this tells the framework to start tracking for
    // a long press and eventual key up. it will only
    // do so if this is the first down (not a repeat).

    event.startTracking();
    return true;
}
(...)

and this part part for the long press:

  @Override
    public boolean onKeyLongPress(int keyCode, KeyEvent event) {

        //Log.i(TAG,"LONG"+keyCode);
        Toast.makeText(Launcher.this,"LONG "+keyCode, Toast.LENGTH_SHORT).show();

        if (keyCode == KeyEvent.KEYCODE_MENU) {
        (...)

But the problem is that I wasn't able to replace the KeyEvent.KEYCODE_MENU with KeyEvent.KEYCODE_HOME

is that something locked in the code that avoid user to use a Home long press?

Thank a lot for all the information you woulg give me.

Reaves answered 29/5, 2010 at 8:28 Comment(0)
N
8

Everything I have ever read states that this can't be done... Here is a post on Android Beginners where I asked a very similar question:

http://groups.google.com/group/android-beginners/browse_thread/thread/d8cdcd1c52d79ef1/0f4b184da6f248a9?lnk=gst&q=home+key#0f4b184da6f248a9

However, I have recently come across an app that successfully allows you to launch it by double-tapping the home key so there has got to be something that can be done. I looked into that approach for a while but couldn't get it to work. Now that I know someone else figured it out I'm going to take another stab at it....

EDIT While overriding a long-press of the home button cannot be done, I have found a way to successfully implement a double-press of the home button. The general idea for this is as follows:

  1. Make your app act as a home replacement app (Look at the sample home app in the SDK samples)
  2. Allow a way in your app to specify a home app to use (it is pretty straightforward to present the user a list of home-replacement apps)
  3. On the first press of the home button start a timer.
  4. If the timer times out, launch the home application
  5. If the user presses the home key a second time before the timer stops, launch your app

Essentially, the home-replacement activity does nothing more than either launch the real home app specified by the user or launch your app... It never displays its own UI.

I have found that this works pretty well, and actually have an app published in the Android Market that does this. If you would like to see it in action, it is called "Quick Launch" and the publisher name is listed as "MagouyaWare"

Hope this helps!

Nunuance answered 8/7, 2010 at 23:18 Comment(1)
So did you find out something new? Which application was it?Cornered
C
5

You can register fake activity for the long press HOME button

by adding to manifest:

<intent-filter>
    ...
    <action android:name="android.intent.action.ASSIST" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Crellen answered 12/11, 2015 at 13:35 Comment(1)
Great ! It works on a Samsung Galaxy View. It works the same as <category android:name="android.intent.category.HOME" />. I would like to have the same for a long press on the task button...Tamp
L
-1

I found a way to tackle HOME key. For your application set the manifest as

<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>

Now your application is an alternate Launcher application.

Use the adb, and disable the launcher application using package manager

pm disable com.android.launcher2.

Now the Home key press will always stay in the same screen.

Actually there is not much code.I will try to explain it if it helps. For the Android application in the manifest file, we generally keep the intent filter as:

<action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.LAUNCHER" /> 

Instead we should make the intent filter look like:

<action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.HOME" /> 
<category android:name="android.intent.category.DEFAULT" />               
<category android:name="android.intent.category.MONKEY"/>

This is the same intent filter as that of Launcher.

Now we have an alternate launcher application. To make it the only launcher application we have to uninstall/disable the existing launcher application (default launcher in Android).

For this we need to connect the device/emulator and start the adb (android debug bridge). Then follow the below steps:

adb shell
# pm list packages //This will list all the packages installed
#pm disable com.android.launcher //This will disable the launcher application.

Reboot.

Loki answered 27/12, 2010 at 11:57 Comment(2)
can you write a guide in your blog,so that you give this link.i found that in many link you give the answer,i think that you can help many people include me.thank youBackman
I gave this a negative rating because it doesn't answer the original question. The original question was how to replace the functionality of a long-press of the home key. This cannot be done. Also, I would highly advise against disabling the default home app. Just because it can be done doesn't mean it should be done. The best way to do what amiekuser suggests is to use the built-in Android method of setting a default application. If you have more than one home replacement app and you press the home key you get a dialog asking you which app to use (and allows you to make it the default)Nunuance

© 2022 - 2024 — McMap. All rights reserved.