栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Android 桌面快捷方式

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android 桌面快捷方式

Android 快捷方式

使用方式
ShortcutUtils.getInstance().addShortcut(this
                    		 , MainActivity2.class
                   			 , liveBundle
                   			 , "live_Id"
                   			 , "看直播"
                   			 , "看直播"
                    		, R.drawable.live)
                    .addShortcut(this
                            , MainActivity2.class
                            ,vodBundle
                            , "vod_Id"
                            , "看回放"
                            , "看回放"
                            , R.drawable.vod)
                    .build();
添加权限
     
     
     
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
ShortcutUtils工具类(直接使用)
public class ShortcutUtils {
    private static ShortcutUtils shortcutUtils;
    private List shortcutInfos;
    private Context mContext;

    public static ShortcutUtils getInstance() {
        if (shortcutUtils == null) {
            synchronized (ShortcutUtils.class) {
                if (shortcutUtils == null) {
                    shortcutUtils = new ShortcutUtils();
                }
            }
        }
        return shortcutUtils;
    }

    private ShortcutUtils() {
        shortcutInfos = new ArrayList<>();
    }

    
    public ShortcutUtils addShortcut(Context context, Class cls, Bundle bundle, String shortcutId, String shortLabel, String longLabel, @DrawableRes int resId) {
        if (shortcutUtils != null && shortcutInfos != null) {
            if (Build.VERSION.SDK_INT >= 25) {
            	mContext = context;
                Intent intent = new Intent(context, cls);
                intent.putExtra("shortcutArgument", bundle);
                intent.setAction(Intent.ACTION_VIEW);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, shortcutId)
                        .setShortLabel(shortLabel)
                        .setLongLabel(longLabel)
                        .setIcon(Icon.createWithResource(context, resId))
                        .setIntent(intent)
                        .build();

                shortcutInfos.add(shortcutInfo);
            }
        }
        return shortcutUtils;
    }


    
    public ShortcutUtils addShortcut(Context context, Intent intent, String shortcutId, String shortLabel, String longLabel, @DrawableRes int resId) {
        if (Build.VERSION.SDK_INT >= 25) {
            mContext = context;
            if (shortcutUtils != null && shortcutInfos != null) {
                ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, shortcutId)
                        .setShortLabel(shortLabel)
                        .setLongLabel(longLabel)
                        .setIcon(Icon.createWithResource(context, resId))
                        .setIntent(intent)
                        .build();

                shortcutInfos.add(shortcutInfo);
            }
        }
        return shortcutUtils;
    }

    
    public void build() {
        if (shortcutInfos != null && shortcutInfos.size() > 0 && mContext != null) {
            ShortcutManager systemService = mContext.getSystemService(ShortcutManager.class);
            systemService.setDynamicShortcuts(shortcutInfos);
        }
    }

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/680459.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号