添加

添加快捷方式是向桌面应用(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. Eclipse 更改默认的编码 和 换行符

  2. [leetcode tree]107. Binary Tree Level Order Traversal II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  3. 第一个ASP.NET MVC应用程序

    首先打开vs2015 文件->新建->项目 选择模版选empty,下面[为下项添加文件夹和核心引用]勾选mvc 点击确定就好

  4. 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)

    A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...

  5. luoguP3952 [NOIP2017]时间复杂度 模拟

    原本只是想看下多久能码完时间复杂度 然后在30min内就码完了,然后一A了???? 首先,这题完全可以离线做 我们先把所有的操作读完,判断合不合法之后,再去判断和标准答案的关系 具体而言 把所有的操作 ...

  6. Mysql 千万级快速查询|分页方案

    1.简单的 直接查主键id SELECT id FROM tblist WHERE LIMIT 500000,10 2对于有where 条件,又想走索引用limit的,必须创建一个索引,将where  ...

  7. JSON在PHP中的基本应用

    从5.2版本开始,PHP原生提供json_encode()和json_decode()函数,前者用于编码,后者用于解码. 一.json_encode() 该函数主要用来将数组和对象,转换为json格式 ...

  8. Flex父子窗体相互调用

    Flex父子窗体相互调用 1.设计思路 (1)子窗体调用父窗体的方法 (2)子窗体做了改动后,返回父窗体,父窗体调用子窗体函数 2.设计源代码 (1)父窗体 ParentWindow.mxml: &l ...

  9. IDA Supported Processors

    IDA supports more than 50 families of processors. The source code of some of the processor modules i ...

  10. 基于tomcat7 web开发中的一点小东西

    控制台: org.apache.jasper.compiler.TldLocationsCache tldScanJar 信息: At least one JAR was scanned for TL ...