7

Anyone who knows how to disable the Recent Task App Button when it launches the allowed application in the app just like in SureLock Kiosk Lockdown? If so, can you please provide codes for that?

Lynn Crumbling
  • 12,601
  • 8
  • 58
  • 92
androidBoomer
  • 3,277
  • 6
  • 29
  • 42

5 Answers5

2

From the source

public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

        Log.d("Focus debug", "Focus changed !");

    if(!hasFocus) {
        Log.d("Focus debug", "Lost focus !");

        Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);
    }
}
Nambi
  • 11,766
  • 3
  • 35
  • 49
2

For disabling Recent button add this code to your Main activity:

@Override 
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (!hasFocus) {
        windowCloseHandler.post(windowCloserRunnable);
    }
}
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();
    }
}
};
0
  @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    Log.d("Focus debug", "Focus changed !");

    if(!hasFocus) {
        Log.d("Focus debug", "Lost focus !");

        Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);
    }
}
RkKhanpuriya
  • 154
  • 1
  • 12
0

Other answers here are a hacky way, I tried those but didn't like. Later I have found that Android provides a library to do similar things. Please look at my answer here: https://stackoverflow.com/a/59266919/1938507

Note: I am directly posting answer not a comment, because I wasted a lot of time on this topic and people usually overlook comments!

Junaed
  • 1,041
  • 9
  • 13
-1

For disable the recent apps button while launching other applications then you can create a service.

public class StatusBarService extends Service {

private static final String TAG = StatusBarService.class.getSimpleName();

private volatile boolean isRunning;

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();

    isRunning = true;

    // Lock a recentApps button
    RecentAppLockerThread thread = new RecentAppLockerThread();
    new Thread(thread).start();

}

/**
 * Lock a recent apps button
 * 
 * 
 */
private class RecentAppLockerThread implements Runnable {

    @Override
    public void run() {
        while (isRunning) {
            Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            sendBroadcast(closeDialog);          
        }
    }

}

@Override
public boolean stopService(Intent name) {
    isRunning = false;
    return super.stopService(name);
}

@Override
public void onDestroy() {
    super.onDestroy();
    isRunning = false;
}

}

Kannappan
  • 11
  • 2
  • 1
    You can't be serious. Infinite closedialog broadcasts while your service is running? Additionally, the stopService override isn't a callback to stop the service; it comes from the context so that code runs when you call stopService from within your service. This answer is harmful. – PaulR Jul 24 '15 at 22:50