How to disable the Recent Tasks/Apps button

后端 未结 5 776
忘掉有多难
忘掉有多难 2020-11-30 02:48

I\'m building a child play application for Android. I need to disable all keys when it is in use. I have set the Application as the Home App and disabled the back key (that

5条回答
  •  无人及你
    2020-11-30 03:31

    This will close the RecentActivity dialog. Put it in your activity class.

        @Override
        public void onWindowFocusChanged(boolean hasFocus) {
            super.onWindowFocusChanged(hasFocus);
    
            if (!hasFocus) {
                windowCloseHandler.postDelayed(windowCloserRunnable, 250);
            }
        }
    
        private void toggleRecents() {
            Intent closeRecents = new Intent("com.android.systemui.recent.action.TOGGLE_RECENTS");
            closeRecents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            ComponentName recents = new ComponentName("com.android.systemui", "com.android.systemui.recent.RecentsActivity");
            closeRecents.setComponent(recents);
            this.startActivity(closeRecents);
        }
    
        private Handler windowCloseHandler = new Handler();
        private Runnable windowCloserRunnable = new Runnable() {
            @Override
            public void run() {
                ActivityManager am = (ActivityManager)getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
                ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
    
                if (cn != null && cn.getClassName().equals("com.android.systemui.recent.RecentsActivity")) {
                    toggleRecents();
                }
            }
        }
    

    You will need to put the following permission in your manifest.

        
    

提交回复
热议问题