You could attempt to disable hardware navigation keys(sound keys, back press etc) disabling the back press and volume keys.
To disable back button
@Override
public void onBackPressed() {
// Leave it blank to disable it;
}
To disable sound keys
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) {
//do nothing
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
//do nothing
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
To Disable Status Bar Dropdown
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY);
setContentView(R.layout.your_layout);
EDIT
To disable status drop down, use this method. This is an overlay over status bar and consumed all input events. It prevents the status from expanding.
Note:
- customViewGroup is custom class which extends any
layout(frame,relative layout etc) and consumes touch event.
- To consume touch event override the onInterceptTouchEvent method of
the view group and return true.
Android Manifest
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
customViewGroup implementation
WindowManager manager = ((WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * getResources()
.getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
customViewGroup view = new customViewGroup(this);
manager.addView(view, localLayoutParams);
To disable Soft Keys
The best way to disable the soft keys is by pinning the app (App Pinning). And finally create the app in immersive mode. You could also set your app as launcher. Then when home button is clicked your app will be called, keeping your app open.
To make this, add two categories.
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
Reference Documentation: https://developer.android.com/work/cosu.html