添加

添加快捷方式是向桌面应用(launcher)发送相关action的广播:

public static final String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";

Code:

private void addShortcut(String name) {
Intent addShortcutIntent = new Intent(ACTION_ADD_SHORTCUT); // 不允许重复创建
addShortcutIntent.putExtra("duplicate", false);// 经测试不是根据快捷方式的名字判断重复的
// 名字
addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); // 图标
addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(MainActivity.this,
R.drawable.ic_launcher)); // 设置关联程序
Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
launcherIntent.setClass(MainActivity.this, MainActivity.class);
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER); addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent); // 发送广播
sendBroadcast(addShortcutIntent);
}

移除

action:

public static final String ACTION_REMOVE_SHORTCUT = "com.android.launcher.action.UNINSTALL_SHORTCUT";

Code:

private void removeShortcut(String name) {

        Intent intent = new Intent(ACTION_REMOVE_SHORTCUT);

        // 名字
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); // 设置关联程序
Intent launcherIntent = new Intent(MainActivity.this,MainActivity.class).setAction(Intent.ACTION_MAIN); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent); // 发送广播
sendBroadcast(intent);
}

权限

<!-- 添加快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<!-- 移除快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

我是天王盖地虎的分割线

Android -- ShortCut的更多相关文章

  1. android shortcut &livefoulder

    android shortcut(实现步骤) 1.建立activity 2.minifest 里面注册并加上intent-filter,name为:android.intent.action.CREA ...

  2. Android 7.1 - App Shortcuts

    Android 7.1 - App Shortcuts 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Shortcuts 文中如有纰漏,欢迎大家留言 ...

  3. Android 7.1 App Shortcuts使用

    Android 7.1 App Shortcuts使用 Android 7.1已经发了预览版, 这里是API Overview: API overview. 其中App Shortcuts是新提供的一 ...

  4. 安卓7.1 新特性Shortcut

    介绍 Shortcut 是谷歌在API25提出来的 类似苹果3D touch 但是没有压力感应.在安卓中完全就是长按. 来看下效果吧: 是不是很赞? 那么请随本文一起学习吧 更新 新建项目 在你项目下 ...

  5. Android 7.1.1 之实现 3D Touch

    转载请注明出处:http://blog.csdn.net/yyh352091626/article/details/68962736 Shortcut概念 详细实现 BuildConfig 配置 静态 ...

  6. Android 7.1 快捷方式 Shortcuts

    转载请注明出处:王亟亟的大牛之路 前些天就看到相关内容了,但是最近吸毒比较深(wow),所以没有紧跟潮流,今天补一篇. 先安利:https://github.com/ddwhan0123/Useful ...

  7. android7/8新特性 画中画、shortcut和分屏模式

    多窗口 在android7.0中原生提供了多窗口模式和画中画模式,多窗口模式将屏幕分为上下或左右两块区域分别显示两个应用,画中画模式主要应用在android TV中,类似于windows中的多窗口. ...

  8. App Shortcuts 快捷方式:Android 的 '3D Touch'

    Hello Shortcuts 从Android7.1(API level25)开始,开发者可以为自己的app定制shortcuts.shortcuts使用户更便捷.快速的使用app.我个人感觉有点像 ...

  9. Android添加快捷方式(Shortcut)到手机桌面

    Android添加快捷方式(Short)到手机桌面 权限 要在手机桌面上添加快捷方式,首先需要在manifest中添加权限. <!-- 添加快捷方式 --> <uses-permis ...

随机推荐

  1. [leetcode greedy]455. Assign Cookies

    Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...

  2. Here is a 10-line template that can solve most 'substring' problems子字符串问题的模板

    转载自leetcode评论区:https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-mo ...

  3. 关于PIP 总结和记忆巩固

    查找需要安装的包 pip search <包名> 安装python包 pip install  pip install <包名>==1.0.4  pip install -r ...

  4. 2018-2019-2 20162318《网络攻防技术》Exp5 MSF基础应用

    1.实验内容 1.一个主动攻击实践,如ms08_067 2. 一个针对浏览器的攻击,如ms11_050) 3. 一个针对客户端的攻击,如Adobe 4. 成功应用任何一个辅助模块 2.基础问题回答 2 ...

  5. 【ACM-ICPC 2018 沈阳赛区网络预赛】不太敢自称官方的出题人题解

    A. Gudako and Ritsuka 链接 by Yuki & Asm.Def 期望难度:Hard- 考虑从后往前进行博弈动态规划,在这一过程中维护所有的先手必胜区间.区间不妨采用左开右 ...

  6. libuuid.so: cannot open shared object file: No such file or directory

    在玩ngx-lua时候有个 resty-uuid 需要引用 libuuid.so 动态库 打印log提示信息是这样的: libuuid.so: cannot open shared object fi ...

  7. C++各大名库

    C++各大名库的介绍之C++标准库 标准库中提供了C++程序的基本设施.虽然C++标准库随着C++标准折腾了许多年,直到标准的出台才正式定型,但是在标准库的实现上却很令人欣慰得看到多种实现,并且已被实 ...

  8. FastBoot BootLoader Recovery 模式解释

    理论上,所有的Android设备都存在着Fastboot/Bootloader模式,不过,由于Android操作系统的开源特性,各厂商的对 自家的相关Android设备都有着各自不同的Fastboot ...

  9. log4j用properties文件配置,无法应用过滤器的解决方法

    properties文件仍然有错误 log4j:WARN Failed to set property [filter] to value "org.apache.log4j.varia.L ...

  10. IOS开发之深拷贝与浅拷贝(mutableCopy与Copy)详解

    copy与retain的区别: copy是创建一个新对象,retain是创建一个指针,引用对象计数加1.Copy属性表示两个对象内容相同,新的对象retain为1 ,与旧有对象的引用计数无关,旧有对象 ...