创建快捷方式

/**
     * 快捷方式
     */

    private void createShortcut() {


        Intent intent = new Intent();

        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        //如果设置为true表示可以创建重复的快捷方式
        intent.putExtra("duplicate", false);

        /**
         * 1 干什么事情
         * 2 你叫什么名字
         * 3你长成什么样子
         */
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "黑马手机卫士");
        //干什么事情
        /**
         * 这个地方不能使用显示意图
         * 必须使用隐式意图
         */
        Intent shortcut_intent = new Intent();

        shortcut_intent.setAction("aaa.bbb.ccc");

        shortcut_intent.addCategory("android.intent.category.DEFAULT");

        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut_intent);

        sendBroadcast(intent);

    }

需要的权限

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> 
posted @ 2016-03-06 00:02  有点理想的码农  阅读(117)  评论(0编辑  收藏  举报