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);
  • 相关阅读:
    php_sphinx安装使用
    深入Web请求过程(笔记)
    php的单例模式
    解决rsync 同步auth failed on module问题
    生成shadow中hash字串
    python程序不支持中文
    xshell4无法使用小键盘问题解决
    LVS客户端启动脚本
    更改linux系统提示信息
    使用md5判断网站内容是否被篡改
  • 原文地址:https://www.cnblogs.com/wuyou/p/3685494.html
Copyright © 2011-2022 走看看