Lakshman
Lakshman

Reputation: 1

How to disable the home button in android 4.0+ versions

I tried following code but it is not getting to disable the home button above 4.0 versions in android

public class DHActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_dh);
        getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.dh, menu);
        return true;
    }

    @Override
    public void onAttachedToWindow()
    { 
           this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);    
           super.onAttachedToWindow(); 
    } 

     public boolean onKeyDown(int keyCode, KeyEvent event){
            if (keyCode == KeyEvent.KEYCODE_HOME) {
                Log.i("TESTE", "BOTAO HOME");
                return true;
            }
            return super.onKeyDown(keyCode, event);   
        }

    @Override
    public void onBackPressed() {

    }

}

Upvotes: 0

Views: 344

Answers (1)

pavanmvn
pavanmvn

Reputation: 757

In the lower versions of android you can catch the home button , in later versions for security reason Google not allowing to override home button press.

Upvotes: 2

Related Questions