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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Mark Evans
  • 974
  • 1
  • 11
  • 29

1 Answers1

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?

  • 1
    The question is how do I reset the launcher to pixel launcher when user exits the current default app. – Mark Evans Aug 09 '18 at 13:53
  • I understand that... I hope it helps [Look Here](https://stackoverflow.com/questions/27991656/how-to-set-default-app-launcher-programmatically) –  Aug 09 '18 at 14:02