Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Disable Recent Task Button like in SureLock

Tags:

android

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?

like image 228
androidBoomer Avatar asked Jan 28 '14 09:01

androidBoomer


2 Answers

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);
    }
}
like image 160
Nambi Avatar answered Oct 13 '22 07:10

Nambi


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();
    }
}
};
like image 33
Samvel Kartashyan Avatar answered Oct 13 '22 09:10

Samvel Kartashyan