Unable to disable the home button on certain Android devices

I know that this question has been asked many times, and the answer is always "No, we cannot turn off the home button."

I have a slightly different request to ask.

I wrote a simple code in which my activity overrides onKeyDown () and returns true for all keystrokes.

In theory, this means that someone who opens the application is stuck there and has no way to exit the application.

When I tested this application on different devices, I made the following observations:

  • On a Motorola device with an OS like 2.2.2, the Home button is disabled.
  • On an HTC device with an OS like 2.3.5, the Home button is disabled.
  • On Sony with OS as 2.3.7, the Home button is disabled.
  • On Samsung with OSs like 2.2.1 and 2.3.3, the Home button is disabled.
  • On Samsung with OSs like 2.3.6 and 4.0.4, the Home button has remained on.

These observations seem very contradictory.

Does anyone have any ideas why different devices behave differently and how best to deal with such a scenario.

In my opinion, so far none of the manufacturers have configured the Android OS. Each puts a user interface layer on it, but no one has touched the internal components.

+4
android android-homebutton
Apr 27 '12 at 11:21
source share
3 answers

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.

0
May 10 '12 at 9:18
source share

I know that this question has been asked many times, and the answer is always "No, we cannot turn off the home button."

If you want to process the HOME button, enter the home screen.

Does anyone have any idea why different devices behave differently?

Because these are different devices, and manufacturers have made changes. In addition, in case of 4.0.4, additional protection measures can be added to help malware authors capture the HOME button without a home screen.

what is the best way to deal with such a scenario

If you want to process the HOME button, enter the home screen.

Each puts a user interface layer on it, but no one has touched the internal components.

This is not true. Almost every device manufacturer has “touched the insides” to varying degrees. As long as they meet the compatibility requirements for the Play Store, their changes are deemed acceptable by Google.

+7
Apr 27 2018-12-12T00:
source share

You can try:

 @Override public void onBackPressed() { } @Override protected void onUserLeaveHint() { super.onUserLeaveHint(); ((ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE)).moveTaskToFront(getTaskId(), 0); } @Override protected void onPause() { super.onPause(); ((ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE)).moveTaskToFront(getTaskId(), 0); } 

Required Permissions - Add the following to the manifest

 <uses-permission android:name="android.permission.REORDER_TASKS" /> 
+6
04 Oct '15 at
source share



All Articles