创建快捷图标到桌面

    /**
     * 创建桌面快捷图标,LAUNCHER 是接收一个广播然后在桌面上创建图标
     * 添加权限:<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
     */
    private void createShutcut() {
        // 防止多次添加,将添加信息保存在本地
        boolean isCreateShortcut = sp.getBoolean(StaticDatas.CONFIG_IS_SHORTCUT_CREATE, false);
        if(isCreateShortcut){
            return;
        }
        
        Intent intent = new Intent();
        
        // 图标: 1.名字   2.图标    3.点击之后打开的页面
        intent.setAction(Intent.ACTION_CREATE_SHORTCUT);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "cbooy手机助手");
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, 
                BitmapFactory.decodeResource(getResources(), 
                        R.drawable.my_launcher));
        
        // 封装图标点击后开启的页面
        Intent shortcutIntent = new Intent();
        shortcutIntent.setAction(Intent.ACTION_MAIN);
        shortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
        
        // 要启动的页面 activity
        shortcutIntent.setClassName(getPackageName(), BootActivity.class.getName());
        
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        sendBroadcast(intent);
        
        // 保存添加的信息
        sp.edit().putBoolean(StaticDatas.CONFIG_IS_SHORTCUT_CREATE, true).commit();
    }
原文地址:https://www.cnblogs.com/cbooy/p/4739787.html