0

Working on a parental control app which sets itself as a default launcher (by presenting user to open chooser and select always). User can exit the app by clicking exit icon on action bar.

Upon exit it should reset the default launcher without presenting user the chooser screen.

How do I set a certain app as default launcher that was approved by user in the past? Some of the apps in playstore are already able to do this.

1
  • Hi @Mark Evans, Did you get any solution for this? Commented May 29, 2020 at 15:28

1 Answer 1

0

Not the ideal solution. But, this can be helpful in solving the problem.

Check for if your application is the default launcher :

private boolean isMyAppLauncherDefault() {
    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);

    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(filter);

    final String myPackageName = getPackageName();
    List<ComponentName> activities = new ArrayList<ComponentName>();
    final PackageManager packageManager = (PackageManager) getPackageManager();

    packageManager.getPreferredActivities(filters, activities, null);

    for (ComponentName activity : activities) {
        if (myPackageName.equals(activity.getPackageName())) {
            return true;
        }
    }
    return false;
}  

Prompt the user to select their default launcher as your launcher :

private void launchAppChooser() {
    Log.d(TAG, "launchAppChooser()");
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

Reference - How to set default app launcher programmatically?

Sign up to request clarification or add additional context in comments.

2 Comments

The question is how do I reset the launcher to pixel launcher when user exits the current default app.
I understand that... I hope it helps Look Here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.