0

I've used the following code for creating shortcut

private void createShortCut() {
        Intent shortcutIntent = new Intent(getApplicationContext(), SplashActivity.class);

        shortcutIntent.setAction(Intent.ACTION_MAIN);

        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().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);
    }

The above code is working well in android 7.0 But it doesn't work in android 8.0 and above. How can I add shortcut into home screen in android 8.0 and above?

Star_Man
  • 1,091
  • 1
  • 13
  • 30

1 Answers1

0

Please refer to this article: https://developer.android.com/guide/topics/ui/shortcuts/creating-shortcuts
You should use ShortcutManager for that purpose.

Denysole
  • 3,903
  • 1
  • 20
  • 28
  • I've already see that document. But that code doesn't create the shortcut in home screen. Thank you for your time. – Star_Man May 14 '19 at 14:40