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,448
  • 23
  • 73
  • 128

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
  • 5,914
  • 2
  • 27
  • 78
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
  • 39,949
  • 51
  • 178
  • 266
-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,879
  • 4
  • 23
  • 49