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