Last active
November 22, 2021 09:04
-
-
Save chuangx/e8ad898db9e70c81263b1f1cd0e14619 to your computer and use it in GitHub Desktop.
Bring your launcher task to front
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TaskManager { | |
/** | |
* Bring up launcher task to front | |
*/ | |
public void navToLauncherTask(@Nonnull Context appContext) { | |
ActivityManager activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE); | |
// iterate app tasks available and navigate to launcher task (browse task) | |
final List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks(); | |
for (ActivityManager.AppTask task : appTasks) { | |
final Intent baseIntent = task.getTaskInfo().baseIntent; | |
final Set<String> categories = baseIntent.getCategories(); | |
if (categories != null && categories.contains(Intent.CATEGORY_LAUNCHER)) { | |
task.moveToFront(); | |
return; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment