ShortcutHelper.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:zapp 作者:
/**
 * Adds the given channel as shortcut to the launcher icon.
 * Only call on api level >= 25.
 *
 * @param context to access system services
 * @param channel channel to create a shortcut for
 * @return true if the channel could be added
 */
@TargetApi(25)
public static boolean addShortcutForChannel(Context context, ChannelModel channel) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    if (shortcutManager == null || shortcutManager.getDynamicShortcuts().size() >= 4) {
        return false;
    }

    ShortcutInfo shortcut = new ShortcutInfo.Builder(context, channel.getId())
        .setShortLabel(channel.getName())
        .setLongLabel(channel.getName())
        .setIcon(Icon.createWithResource(context, channel.getDrawableId()))
        .setIntent(ChannelDetailActivity.getStartIntent(context, channel.getId()))
        .build();

    try {
        return shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
    } catch (IllegalArgumentException e) {
        // too many shortcuts
        return false;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号