androidbuttonandroid-homebutton

How to disable back,home,multitask physical buttons?


Actually i'm developing an app and just this app should be opened on the device where is installed so i would be able to block / disable physical buttons for back,home,multitask.

I've read yet some articles about how to do it but still can't get how to implement it in my app.

The buttons i would disable are the following that you can see on the photo enter image description here


Solution

  • //Just put below code onStart() method

    @Override
        protected void onStart() {
            super.onStart();
            // start lock task mode if it's not already active
            ActivityManager am = (ActivityManager) getSystemService(
                    Context.ACTIVITY_SERVICE);
            // ActivityManager.getLockTaskModeState api is not available in pre-M.
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                if (!am.isInLockTaskMode()) {
                    startLockTask();
                }
            } else {
                if (am.getLockTaskModeState() ==
                        ActivityManager.LOCK_TASK_MODE_NONE) {
                    startLockTask();
                }
            }
    
    
        }