Published app making 2 shortcuts and debug 1

304 views Asked by At

I have published my app now and found that it is creating two shortcut icons where as when I install through android studio it creates only one shortcut. I have added duplicate false and sharedpreference has also been used to check once icon is created. Why the app behaving different and how can I fix it now? This is my code for creating shortcut.

   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);
}

and before calling above method I have below code which runs on activity start.

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

There are 1 answers

2
Bill On BEST ANSWER

When you install from Android Studio (directly from an .apk), no shortcut is made. However, apps installed from the Google Play Store will automatically sometimes create a shortcut after installation.

So when a user installs your app from the play store, two shortcuts are made, one from your app and one from the installation.

EDIT: This solution might prove useful to you: How to detect shortcut in Home screen