0

我现在已经发布了我的应用程序,发现它正在创建两个快捷方式图标,而当我通过 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();
            }
4

1 回答 1

0

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

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

编辑:此解决方案可能对您有用:如何检测主屏幕中的快捷方式

于 2017-01-11T16:26:57.907 回答