DEV Community

Imran khan
Imran khan

Posted on

Activity ShortCut is not create in Vivo devices

I want to create the Activity shortcut at home screen , so user can open the activity screen directly .

I have used this code

if(ShortcutManagerCompat.isRequestPinShortcutSupported
(getApplicationContext()))
{

    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(getApplicationContext(), id)
     .setIntent(new Intent(getApplicationContext(), 
       TranslateActivity.class).setAction(Intent.ACTION_MAIN))
     .setShortLabel(label)
     .setIcon(icon)
     .build();
     return 
Enter fullscreen mode Exit fullscreen mode

ShortcutManagerCompat.requestPinShortcut(getApplicationContext(),
shortcut, startHomeScreen());
}

 else
     {
    // Shortcut is not supported by your launcher

    Intent shortcutIntent = new Intent(getApplicationContext(), TranslateActivity.class);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Test");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher));
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getApplicationContext().sendBroadcast(addIntent);
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)