As mentioned in my question for devices below 2.3.6, OSs that override keypress() functions work well.
The problem starts with 2.3.6 and higher. I do not know what these devices did, but the keypress() function does not work on all devices equally.
In addition, with ICS, google stopped using the keypress() function once for all.
So how do we do it.
As I see it, if we try to redefine the home button, then it is impossible, but definitely we can listen to it.
In our Android manifest, we use the filter <category android:name="android.intent.category.HOME" /> , than this makes our work as a replacement home screen. Now, when you press the home button, a pop-up window will appear with permission for the content and ask which application launches by default or your application should respond to pressing the home button. You can always choose your application.
But this does not cancel or disable the home button. whenever you press the home button, the same thing will be repeated over and over until you make your default application by clicking on the "Use default" checkbox indicated in the pop-up ad.
Now that you have selected your default application, a home press always launches your application.
Done ... no. The problem that arises is that if you exit the application, the home button still launches your application. How to get rid of it as soon as your work is completed.
What we need to do is close or call finish () for our activity, before that we must set the package parameter to its default value using:
paramPackageManager1.setComponentEnabledSetting(localComponentName2, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 1);
This will disable the home button from your activity.
dexprab May 10 '12 at 9:18 a.m. 2012-05-10 09:18
source share