【问题标题】:Published app making 2 shortcuts and debug 1发布的应用程序制作 2 个快捷方式和调试 1
【发布时间】:2017-01-11 16:00:18
【问题描述】:

我现在发布了我的应用程序,发现它正在创建两个快捷方式图标,而当我通过 android studio 安装时它只创建一个快捷方式。我添加了重复的 false 并且 sharedpreference 也已用于检查创建图标后。为什么应用程序的行为不同,我现在该如何解决?这是我创建快捷方式的代码。

   public void createShortCut() {

    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(StartupActivity.this).edit();
    editor.putBoolean("shortcut", true).apply();
    Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutintent.putExtra("duplicate", false);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Smart App");
    Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), SplashScreen.class));
    sendBroadcast(shortcutintent);
}

在调用上述方法之前,我有以下在活动开始时运行的代码。

 if (!sharedPreferences.getBoolean("shortcut", false)) {
                createShortCut();
            }

【问题讨论】:

  • Play 商店会自动创建快捷方式。所以你也不应该创建一个。完全删除您的代码。

标签: java android uiapplicationshortcutitem


【解决方案1】:

当您从 Android Studio(直接从 .apk)安装时,不会创建快捷方式。但是,从 Google Play 商店安装的应用会自动在安装后有时会创建一个快捷方式。

因此,当用户从 Play 商店安装您的应用时,会创建两个快捷方式,一个来自您的应用,一个来自安装。

编辑:此解决方案可能对您有用:How to detect shortcut in Home screen

【讨论】:

  • AppStore 中的应用程序有时会创建快捷方式,我无法检查是否已经创建了快捷方式。
  • 你的观点是正确的,Play商店中有设置创建快捷方式,这会导致重复的快捷方式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多