如何调出设置默认启动的提示? [英] How to bring up the set default launcher prompt?

查看:121
本文介绍了如何调出设置默认启动的提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测是否我的桌面应用是默认启动的,如果没有弹出一个提示,让用户选择我的应用程序为默认启动。我现在面临的问题是,该提示出现,而不选择就一次和总是。此外,选择在我的桌面应用不设置默认值。

在我的onCreate我有以下的检查,看是否我的应用程序是默认启动程序,然后我推出一个对话框,意图使用户可以选择我的应用程序为默认启动。

 如果(!isMyAppLauncherDefault()){
        意向意图=新意图(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        startActivity(Intent.createChooser(意向设置为默认启用Kiosk模式));
    }

下面是我的检查,如果我的应用程序是默认的启动方式

 私人布尔isMyAppLauncherDefault(){
    最后IntentFilter的过滤器=新的IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);    清单<&的IntentFilter GT;过滤器=新的ArrayList<&的IntentFilter GT;();
    filters.add(过滤器);    最后弦乐myPackageName = getPackageName();
    清单<&组件名GT;活动=新的ArrayList<&组件名GT;();
    最终的软件包管理系统软件包管理系统=(软件包管理系统)getPackageManager();    //你可以用你的包的名字作为这里的第三个参数
    packageManager.get preferredActivities(过滤器,活动,NULL);    对于(组件名活动:活动){
        如果(myPackageName.equals(activity.getPackageName())){
            返回true;
        }
    }
    返回false;
}

请注意:我试图改变我如何启动我的意图(见下文code段)。但随后的启动不上来的。什么都没发生。

 意向意图=新意图(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(意向);

我怎样才能始终按钮来显示,并哪能设置实际的默认启动设置。谢谢你在前进!


解决方案

  

我现在面临的问题是,该提示出现,而不选择就一次和总是。


createChooser()引起的 - 那是专为一次性选择器,没有选项使默认。删除您的 createChooser()呼叫,并且只使用意图所构造。如果没有缺省启动程序,用户将得到标准的选择器的就一次和总是的选项。

但是请注意,如果另一个的发射器是默认的,那么你的意图只是到发射路线。没有什么可以真正做到在这种情况下,除了提供指导用户进入设置,删除该应用程序的默认关联。

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!

解决方案

The issue I am facing is that the prompt comes up without the options "Just Once" and "Always".

The createChooser() is causing that -- that is designed for a one-off chooser, with no option for making a default. Remove your createChooser() call, and just use the Intent that you constructed. If there is no default launcher, the user will get the standard chooser with the "Just Once" and "Always" options.

Note, though, that if another launcher is the default, then your Intent will just route to that launcher. There is nothing you can really do in this case, other than to provide guidance to the user to go into Settings and remove their default association for that app.

这篇关于如何调出设置默认启动的提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆