10

I was trying to create app shortcut at home. I did that quite well for most devices.
with this

private void setShortcutIcon() {
        if (ShortcutManagerCompat.isRequestPinShortcutSupported(this)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                final ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
                final ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(this, "334")
                        .setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                        .setShortLabel(getString(R.string.app_name))
                        .setIntent(new Intent(this, SplashActivity.class).setAction(Intent.ACTION_VIEW).putExtra("duplicate", false))
                        .build();
                shortcutManager.requestPinShortcut(pinShortcutInfo, null);
            } else {
                final Intent shortcutIntent = new Intent(getApplicationContext(), SplashActivity.class);
                shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                final Intent addIntent = new Intent();
                addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
                addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
                addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher));
                addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                addIntent.putExtra("duplicate", false);
                getApplicationContext().sendBroadcast(addIntent);
            }
        }
    }

Except for devices having installed apps on home by-default, so in this case there was installed app icon on home already and one more duplicate icon was getting created as shortcut, which is not the expected behaviour.

So I started looking for this differentiation.

I want to know if the current app launcher has dedicated menu button or swipe up behaviour(Nougat, Oreo & Pie) for app list or apps are shown on home by default.

For e.g. mostly stock android phones have the launcher with menu button to check app list.

with menu

And other ROM like MIUI has default launcher where apps get's placed on home by default.

enter image description here

any help/suggestion appreciated, Thanks in advance.

Anu Padhye
  • 615
  • 1
  • 6
  • 16
Man
  • 2,720
  • 2
  • 13
  • 21
  • One approach could be to remove any existing shortcut (even for the first time) and then adding a new fresh one. – TheAnkush Apr 24 '19 at 03:29
  • That won't work since the problem here is not duplicated shortcut, it's the app itself and the shortcut that would be "duplicate" in the home screen if the device puts all its apps in the homescreen – Jack Apr 24 '19 at 04:17
  • Right, @jackz314 ... – Man Apr 24 '19 at 10:37

0 Answers0