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

原文链接:Activity ShortCut is not create in Vivo devices

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容