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

☆樱花仙子☆ 提交于 2019-11-27 14:09:17

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!

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>

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 ur 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 laways stay in the same screen.

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

Instaed we should make the intent filter look like:-


This is the same intent filter as that of LAuncher.

Now we have an alternate launchjer application. To make it the only launcher application we have to unistall/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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!