1

In my app i have to disable device's Home key, my tab supports android 4.4.2

I know how to disable back button functionality, i used below lines for that

@Override
public void onBackPressed() {
}

but i am concern about How to disable Home button functionality ?

I tried below code to disable home button but did not get any help

// to disable home button -- START --   
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if(keyCode == KeyEvent.KEYCODE_HOME)
    {
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
// to disable home button -- END --
Sun
  • 6,768
  • 25
  • 76
  • 131
  • take a look at this [SO Post](http://stackoverflow.com/a/2080353/3326331), you can try overriding `onKeyDown()` for keyCode `KeyEvent.KEYCODE_HOME`, but its highly unreliable, sometimes the method is not called for Home Button – Sagar Pilkhwal Sep 23 '14 at 09:04
  • but any how I have to disable home button – Sun Sep 23 '14 at 09:06
  • try [link](http://stackoverflow.com/a/14601640/2884893) this it worked on my 4.0.4 – The Billionaire Guy Aug 25 '16 at 11:08

3 Answers3

0

Try overriding onKeyDown()

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if(keyCode == KeyEvent.KEYCODE_HOME)
    {
        Log.d("Test", "Home button pressed!");
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
Sagar Pilkhwal
  • 3,998
  • 2
  • 25
  • 77
0

No.... You cannot override home button for Android4.0 and above

This is for security reasons.


Check this answer from Commonsware for more information

Community
  • 1
  • 1
Devrath
  • 42,072
  • 54
  • 195
  • 297
-1
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
    // put your logic here.
     }
return true;
}

or you can try this:

ActionBar actionBar;
    actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
rupesh
  • 2,865
  • 4
  • 24
  • 50