1. 需要权限:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> 
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

2. 判断是否创建

/**
* 判断快捷方式是否创建
* @param context
* @param name 快捷方式名称
* @return
*/
public static boolean hasShortcut(Context context, String name) {
boolean isInstallShortcut = false;
final ContentResolver cr = context.getContentResolver();
final String AUTHORITY = "com.android.launcher.settings";
final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/favorites?notify=true");
Cursor cursor = null;
try {
cursor = cr.query(CONTENT_URI, new String[] { "title",
"iconResource" }, "title=?", new String[] { name }, null);
if (cursor != null && cursor.getCount() > 0) {
isInstallShortcut = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
} return isInstallShortcut;
}
3. 创建快捷方式
/**
* 添加快捷方式
*/
public static void addShortcut(Activity activity, String name, int resourceId) { Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); // 快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
shortcut.putExtra("duplicate", false); // 不允许重复创建 // 指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer
// 注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序 /**************************** 此方法已失效 *************************/
//ComponentName comp = new ComponentName(activity.getPackageName(), "." + activity.getLocalClassName());
//shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); // 快捷方式的图标
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(activity, resourceId);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); // 添加要做的事情
Intent todo = new Intent(Intent.ACTION_MAIN);
todo.setClassName(activity, activity.getClass().getName());
todo.putExtra("test1", "test");
// 点击快捷方式 进行 todo 操作
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, todo); activity.sendBroadcast(shortcut); }

4.删除快捷方式

/**
* 删除快捷方式
*/
public static void delShortcut(Activity activity, String name) {
Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT"); // 快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
String appClass = activity.getPackageName() + "." +activity.getLocalClassName();
ComponentName comp = new ComponentName(activity.getPackageName(), appClass);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
activity.sendBroadcast(shortcut); }
 

Android 快捷方式的更多相关文章

  1. Android 快捷方式相关操作

    尽管现在少数手机不支持快捷方式,但是仍然有大部分手机是支持的.创建快捷方式,可以减少用户在应用列表繁多的应用程序中查找应用的时间,快速进入应用:或是应用中的某个功能使用频率较高,创建快捷方式,可以快速 ...

  2. 【转】Android 快捷方式的创建

    http://blog.csdn.net/lenmoyouzi/article/details/16939977 一.在日常开发中,我们经常会遇到这样的需求就是网桌面添加快捷方式:常见的快捷方式有两种 ...

  3. Android 快捷方式的创建与查询 快捷方式问题大全 获取快捷方式在Launcher数据库中的信息 Failed to find provider info for com.android.la

    /** * 创建添加快捷方式 * 其中需要设置的有: * 1. 快捷方式的标题 * 2. 快捷方式的图标 * 3. 点击快捷方式后的跳转 */ public static void createSho ...

  4. 张高兴的 Xamarin.Forms 开发笔记:Android 快捷方式 Shortcut 应用

    一.Shortcut 简介 Shortcut 是 Android 7.1 (API Level 25) 的新特性,类似于苹果的 3D Touch ,但并不是压力感应,只是一种长按菜单.Shortcut ...

  5. android仿微信红包动画、Kotlin综合应用、Xposed模块、炫酷下拉视觉、UC浏览器滑动动画等源码

    Android精选源码 仿微信打开红包旋转动画 使用Kotlin编写的Android应用,内容你想象不到 Android手机上的免Root Android系统日志Viewer 一个能让微信 Mater ...

  6. 面向忙碌开发者的 Android

    面向忙碌开发者的 Android passiontim 关注 2016.11.19 21:41* 字数 4013 阅读 2967评论 2喜欢 92 面向忙碌开发者的 Android 视频教程(Tuts ...

  7. [转] 给ubuntu中的软件设置desktop快捷方式(以android studio为例)

    原文链接:http://www.cnblogs.com/kinyoung/p/4493472.html ubuntu的快捷方式都在/usr/share/applications/路径下有很多*.des ...

  8. 实现Android桌面的App快捷方式

    本文描述的是,在App开发过程中,该如何实现App在Anroid桌面上生成App的快捷方式.主要分为两个步骤: 一,在AndroidManifest.xml中声明相关权限: <uses-perm ...

  9. 给ubuntu中的软件设置desktop快捷方式(以android studio为例)

    ubuntu的快捷方式都在/usr/share/applications/路径下有很多*.desktop(eclipse的快捷方式也可以类似设置) 下面就建立我们的studio sudo gedit ...

随机推荐

  1. I/O端口与I/O内存

    端口的概念:设备通过系统总线上的接口与CPU相连,接口电路中含有多种寄存器,CPU向设备读写数据实际上是向接口上的寄存器读写数据,这些寄存器称为I/O端口.一个接口通常包含控制端口,数据端口,状态端口 ...

  2. ubuntu zend-eclipse-php debugger调试

    1 下载zendDebugger http://www.zend.com/en/products/studio/downloads?src=downloadb 在这个页面中找到zend debugge ...

  3. leetcode problem 31 -- Next Permutation

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  4. write() ,read();

    int main1(int argc ,char *argv[]){ if(argc < 2 ) return 0; int fd = open(argv[1] , O_RDONLY); if( ...

  5. C#基础(一)——C#中反斜杠/n与/r的区别

    最近在公司实习的过程中,遇到了字符串换行的问题,百度了一下,发现字符串换行的问题还挺多,总结一下最基本的点,以防忘记. \n—>换行符(New Line),作用为换行符后面的字符串显示到“下一行 ...

  6. 基于ActiveMQ的点对点收发消息

    ActiveMQ是apache的一个开源消息引擎.可以作为即通引擎或者消息中间件引擎. 准备 下载ActiveMQ http://activemq.apache.org/download.html 进 ...

  7. 服务器端启动soket多线程

    方法一: Socket socket=null try{ ServerSocket serversocket=nwe ServerSocket(8080) while(true){ socket=se ...

  8. C/C++易错点

    问:void print( int arr[][], int size );这个函数声明是对是错? 当然是错的了,这个根本不是什么函数声明的问题,而是数组声明的问题,int arr[][]这个声明就是 ...

  9. ARM 的Thumb状态测试

    作为一个使用ARM的学习者,有必要全面了解你的处理器内核.尽管有些内容可能在实际应用中用不到,但是“了解”还是很必要的.Thumb状态,是ARM的一个特色,但是你知道Thumb状态与ARM状态最大的区 ...

  10. html5应用程序标签

    一.html5应用程序标签 (1)datalist需要数据载体 input list属性指向数据源 <input type="text" list="input_l ...