【问题标题】:Android custom launcher that launches the default Launcher启动默认启动器的 Android 自定义启动器
【发布时间】:2014-02-27 05:36:23
【问题描述】:

作为我的第一个 Android 应用,我正在编写一个用于工作用途的信息亭。此应用设置为默认启动器和全屏,因此,当平板电脑启动时,自助服务终端已经启动,用户无法打开其他应用或退出自助服务终端应用。

我无法编写代码的最后一件事是能够从我的信息亭/启动器更改为默认的 Android 启动器。我已经准备好密码输入:如果密码正确,我想启动Launcher。

这是我目前所拥有的:

if (message.equals("password")) {
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.HOME");
    startActivity(Intent.createChooser(intent, "Scegli:"));
}

我只在 Android Studio 的模拟器中尝试过这个应用程序,其中默认启动器是 Android 启动器:按照这些说明,应用程序只需在默认的 Android 启动器上运行。所以我想,在平板电脑上,尽管有 createChooser,我只能到达默认启动器,这将是我的信息亭。

【问题讨论】:

标签: android android-intent launcher android-launcher kiosk-mode


【解决方案1】:

这是 OP 的解决方案,从问题正文迁移到这里

if (message.equals("password")) {
    getPackageManager().clearPackagePreferredActivities(getPackageName());
    final Intent intent = new Intent();
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    startActivity(intent);
}

【讨论】:

    【解决方案2】:

    尝试像这样设置您的 Intent:

    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    

    【讨论】:

    • 请阅读 CATEGORY_LAUNCHER 和 CATEGORG_HOME 的文档。
    猜你喜欢
    • 2018-01-01
    • 2014-03-07
    • 2017-01-18
    • 2011-10-06
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 2017-10-21
    • 2017-07-08
    相关资源
    最近更新 更多