How to disable home and back buttons?
Asked
Active
Viewed 595 times
0
-
you can override onBackPressed in Activity to prevent closing activity. – AIMIN PAN Nov 01 '18 at 08:14
2 Answers
0
Use this method to disable the Home key in Android.
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
Use onBackPressed() method to disable the Back key in Android.
@Override
public void onBackPressed()
{
}
Sagar Zala
- 4,361
- 9
- 29
- 58
-
Sorry for bothering you, but when I added this code the programme closed – user7096093 Nov 01 '18 at 09:24
-
-
https://gist.github.com/belalmomani/5ad8e6ca2441c7c03af567ec540c5a3a – user7096093 Nov 01 '18 at 09:41
-
It's closed immediately without giving any error there is no error log – user7096093 Nov 01 '18 at 09:45
0
Home Button:
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
To disable Home Button:
@Override
public void onAttachedToWindow() {
// TODO Auto-generated method stub
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
To disable Back Button:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Do nothing or catch the keys you want to block
}
To add this in your Android Manifest:
<uses-permission android:name="android.permission.REORDER_TASKS" />
PartTimeNerd
- 295
- 1
- 2
- 18