I want to detect if my launcher app is the default launcher, and if not bring up a prompt to have the user choose my app as the default launcher. The issue I am facing is that the prompt comes up without the options "Just Once" and "Always". Additionally, selecting on my launcher app does not set the default.
In my onCreate I have the following check to see if my app is the default launcher, and then I launch a dialog with intent so that user can choose my app as the default launcher.
if (!isMyAppLauncherDefault()) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, "Set as default to enable Kiosk Mode"));
}
Here is my method for checking if my app 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();
// You can use name of your package here as third argument
packageManager.getPreferredActivities(filters, activities, null);
for (ComponentName activity : activities) {
if (myPackageName.equals(activity.getPackageName())) {
return true;
}
}
return false;
}
Note: I have tried changing how I launch my intent (see code snippet below). But then the launcher does not come up at all. Nothing happens.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
How can I get the ALWAYS button to display, and how can I set the actual default launcher settings. Thank you in advance!