如何调出设置的默认启动器提示?
How to bring up the set default launcher prompt?
我想检测我的启动器应用程序是否是默认启动器,如果不是,则提示让用户选择我的应用程序作为默认启动器。我面临的问题是出现的提示没有 "Just Once" 和 "Always" 选项。此外,在我的启动器应用程序上选择不会设置默认值。
在我的 onCreate 中,我进行了以下检查以查看我的应用程序是否是默认启动器,然后我启动了一个带有意图的对话框,以便用户可以选择我的应用程序作为默认启动器。
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"));
}
这是我检查我的应用程序是否为默认启动器的方法
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;
}
注意:我已尝试更改启动 intent 的方式(请参阅下面的代码片段)。但是随后启动器根本没有出现。什么都没发生。
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);
如何显示“始终”按钮,以及如何设置实际的默认启动器设置。提前致谢!
The issue I am facing is that the prompt comes up without the options "Just Once" and "Always".
createChooser()
导致了这种情况 -- 这是为一次性选择器设计的,没有用于设置默认值的选项。删除您的 createChooser()
调用,并仅使用您构建的 Intent
。如果没有默认启动器,用户将获得带有 "Just Once" 和 "Always" 选项的标准选择器。
请注意,如果 另一个 启动器是默认启动器,那么您的 Intent
将只路由到该启动器。在这种情况下,您实际上无能为力,只能指导用户进入“设置”并删除他们与该应用的默认关联。
我想检测我的启动器应用程序是否是默认启动器,如果不是,则提示让用户选择我的应用程序作为默认启动器。我面临的问题是出现的提示没有 "Just Once" 和 "Always" 选项。此外,在我的启动器应用程序上选择不会设置默认值。
在我的 onCreate 中,我进行了以下检查以查看我的应用程序是否是默认启动器,然后我启动了一个带有意图的对话框,以便用户可以选择我的应用程序作为默认启动器。
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"));
}
这是我检查我的应用程序是否为默认启动器的方法
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;
}
注意:我已尝试更改启动 intent 的方式(请参阅下面的代码片段)。但是随后启动器根本没有出现。什么都没发生。
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);
如何显示“始终”按钮,以及如何设置实际的默认启动器设置。提前致谢!
The issue I am facing is that the prompt comes up without the options "Just Once" and "Always".
createChooser()
导致了这种情况 -- 这是为一次性选择器设计的,没有用于设置默认值的选项。删除您的 createChooser()
调用,并仅使用您构建的 Intent
。如果没有默认启动器,用户将获得带有 "Just Once" 和 "Always" 选项的标准选择器。
请注意,如果 另一个 启动器是默认启动器,那么您的 Intent
将只路由到该启动器。在这种情况下,您实际上无能为力,只能指导用户进入“设置”并删除他们与该应用的默认关联。