zoukankan      html  css  js  c++  java
  • Android 通过程序添加桌面快捷方式

    原理:通过代码向 Launcher 中的广播接收者发送广播来创建快捷图标

    首先要声明的权限是:

        <!--添加图标的权限-->
        <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
            //创建用于发送广播的intent
            Intent broadcastIntent = new Intent();
            // 指定动作名称
            broadcastIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            // 指定快捷方式的图标
            Parcelable icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
            broadcastIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
            // 指定快捷方式的名称
            broadcastIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式的名称");
            // 指定快捷图标激活哪个activity
            Intent activityIntent = new Intent();
            activityIntent.setAction(Intent.ACTION_MAIN);
            activityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            ComponentName component = new ComponentName(this, MyActivity.class);
            activityIntent.setComponent(component);
            broadcastIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, activityIntent);
            // 只创建一次快捷方式
            broadcastIntent.putExtra("duplicate", false);
            sendBroadcast(broadcastIntent);
  • 相关阅读:
    扫描线算法
    [Baltic 2001]Mars Maps
    Lost Cow
    李超线段树
    多种方法求解Pku3468 A Simple Problem with Integers
    陈老师的福利
    leetcode 673. 最长递增子序列的个数
    #10043.「一本通 2.2 例 1」剪花布条
    PTA7-1
    6-1 实验三哈夫曼树 (15分)
  • 原文地址:https://www.cnblogs.com/wuyou/p/3685494.html
Copyright © 2011-2022 走看看