How can I enable or disable the home button on Android tablets?
Asked
Active
Viewed 2,541 times
0
-
You mean the home button? – Razgriz Jul 13 '13 at 06:53
-
fortunatelly home button cannot be disabled – pskink Jul 13 '13 at 07:02
-
1Its like an `emergency` button for the user. Why would you want to take that away from them? – Shobhit Puri Jul 13 '13 at 07:03
-
@ShobhitPuri for online transaction so only i want to disable that – Nas Jul 13 '13 at 07:06
-
when u want enable & when you want to disable it – Yogesh Tatwal Jul 13 '13 at 07:09
-
@YogeshTatwal at the time of payment process initiated i want to disable and after complete process it will enable – Nas Jul 13 '13 at 07:12
-
http://stackoverflow.com/a/15459920/1915697 please see this link – Yogesh Tatwal Jul 13 '13 at 07:19
-
also see this link http://stackoverflow.com/a/9825766/1915697 – Yogesh Tatwal Jul 13 '13 at 07:24
-
There is no way to detect the HOME button pressed. One way you can handle it is that if your transaction is on UI thread, then you can check in `onPause()` method if the person is trying to pause the activity or sth. Other way which I can think of it to start a background process and do that transaction thing from there. – Shobhit Puri Jul 13 '13 at 07:25
-
http://stackoverflow.com/questions/17183905/how-to-disable-home-button-in-android/17183967#17183967. you cannot disable home button. If you want to handle the HOME button, implement a home screen. – Raghunandan Jul 13 '13 at 07:41
-
Thank you so much to all for sharing your ideas. – Nas Jul 13 '13 at 08:41
3 Answers
2
Overriding the Home button - how do I get rid of the choice?
you can, but it's dangerous
also, this question has been asked multiple times in the past
1
By implementing Overided methods onAttachedToWindow() and onKeyDown() it's work fine.
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
MainActivity.this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
Log.d("Home Button", "Clicked");
}
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
}
return false;
};
Without overriding onAttachedToWindow method KEYCODE_HOME doesn't work.
Note:Home key press is handled by the framework and is never delivered to applications.
This is a flaw in version <4.0 and is not working from ICS.
Nas
- 2,088
- 1
- 17
- 35
-1
Try this code.
@Override
public void onAttachedToWindow() {
Log.i("TESTE", "onAttachedToWindow");
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
Zulfiqar Chandio
- 326
- 2
- 7