1: 创建快捷方式

需要权限: <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> 

private static void createShortcut(Context cxt, String shortcutName, int shortcutIconRes,
String className, boolean duplicate, boolean laucherCategory) { Intent intent = getShortCutIntent(cxt, cxt.getPackageName(), className, shortcutName,
laucherCategory);
int iconsize = cxt.getResources().getDimensionPixelSize(Res.dimen.app_icon_size);
BitmapDrawable icon = (BitmapDrawable) cxt.getResources().getDrawable(shortcutIconRes);
Bitmap bmp = ImageUtils.scaleTo(icon.getBitmap(), iconsize, iconsize, false);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bmp);
intent.putExtra(EXTRA_SHORTCUT_DUPLICATE, duplicate); // Now, notify the launcher to create the shortcut
cxt.sendBroadcast(intent);
}
private static Intent getShortCutIntent(Context cxt, String pkgName, String className,
String shortcutName, boolean laucherCategory) {
// Prepare the intents for shortcut
Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
shortcutIntent.setClassName(pkgName, className);
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.putExtra(Constants.EXTRA_FROM_KEY, Constants.EXTRA_FROM_VALUE_SHORTCUT);
if (laucherCategory) {
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutIntent.setAction(Intent.ACTION_MAIN);
} Intent intent = new Intent(ACTION_INSTALL_SHORTCUT);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
return intent;
}

2:删除快捷方式(MIUI系统不支持):

需要权限:<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

public static void removeShortcut(Context cxt, String shortcutName, String className,
boolean removeAll) {
// Prepare the intents for shortcut
Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
shortcutIntent.setClassName(cxt, className); Intent intent = new Intent(ACTION_UNINSTALL_SHORTCUT);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
intent.putExtra(EXTRA_SHORTCUT_DUPLICATE, removeAll); // Now, notify the launcher to remove the shortcut
cxt.sendBroadcast(intent);
}

3:查询快捷方式是否存在(三方rom大部分查询失败,cursor为null)

需要权限:<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />

或者      <uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS" />

private boolean hasShortcut()
{
boolean isInstallShortcut = false;
final ContentResolver cr = activity.getContentResolver();
final String AUTHORITY ="com.android.launcher.settings";
final Uri CONTENT_URI = Uri.parse("content://" +AUTHORITY + "/favorites?notify=true");
Cursor c = cr.query(CONTENT_URI,new String[] {"title","iconResource" },"title=?",
new String[] {getString(R.string.app_name).trim()}, null);
if(c!=null && c.getCount()>0){
//String title = c.getString(c.getColumnIndexOrThrow("title"));
isInstallShortcut = true ;
}
return isInstallShortcut ;
}

[Android Pro] 创建快捷方式,删除快捷方式,查询是否存在快捷方式的更多相关文章

  1. Python创建、删除桌面、启动组快捷方式的例子分享

    一.Python创桌面建快捷方式的2个例子 例子一: 代码如下: import osimport pythoncomfrom win32com.shell import shell    from w ...

  2. [Android Pro] root用户删除文件提示:Operation not permitted

    reference to : http://blog.csdn.net/evanbai/article/details/6187578 一些文件看上去可能一切正常,但当您尝试删除的时候,居然也会报错, ...

  3. Android创建和删除桌面快捷方式

    有同学方反馈创建快捷方式后,点击快捷方式后不能启动程序或者提示"未安装程序",貌似是新的rom在快捷方式这块做过修改(由于此文是11年5月所出,估计应该是2.0或2.1的rom), ...

  4. 用注册表创建无法删除的IE快捷方式

    代码如下: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{98745625-1234 ...

  5. android 多个shortCut快捷方式实现以及对58同城快捷方式的实现思路的研究

    这几天,项目中有个新需求,需要按照模块添加不同的快捷方式到桌面上,从而方便用户的使用.特意进行了研究并分析了下58上面桌面快捷方式的实现. 首先多个shortcut的实现: <activity ...

  6. Elasticsearch 使用:创建、插入、查询、更新、删除

    Elasticsearch 是一个开源的搜索引擎,建立在一个全文搜索引擎库 Apache Lucene™ 基础之上. Lucene 可能是目前存在的,不论开源还是私有的,拥有最先进,高性能和全功能搜索 ...

  7. 百度——LBS.云 v2.0——云存储的POI创建和删除--Android 源码

    如有疑问请联系:QQ936467727 需要注意的几点问题: 1.密钥是http://lbsyun.baidu.com/apiconsole/key申请的,密钥类型是浏览器端 2.geotable_i ...

  8. Android创建或删除了文件,在电脑端查看的时候,却没有对应的变化,处理办法

    在Android应用中,碰到一个问题,在代码中执行创建或者删除某个文件后,在系统的文件管理器中能够相应地看到文件的变化,但是插在电脑上查看的时候,却看不到改文件的变化.同时,当创建文件后,在系统中的某 ...

  9. MYSQL语句:创建、授权、查询、修改、统计分析等 一 用户的创建、权限设置、删除等

    MYSQL语句:创建.授权.查询.修改.统计分析.. 一.用户的创建.权限设置.删除等 1.首先链接MySQL操作 连接格式:mysql -h 主机地址 -u 用户名 -p 用户密码 (注-u与roo ...

随机推荐

  1. 如何在阿里云esc上安装wordpress

    本人的个人网纱建好,但是由于新申请的域名还没有备案 所以暂时无法通过域名访问. 1.按顺序边看边跟着做基本上你能够很优雅的完成大部分设置. http://bbs.aliyun.com/read/162 ...

  2. 虚拟存储管理中几种缺页中断算法(最佳置换法OPT)

    缺页中断就是要访问的页不在主存,需要操作系统将其调入主存后再进行访问. 在进行内存访问时,若所访问的页已在主存,则称此次访问成功: 若所访问的页不在主存,则称此次访问失败,并产生缺页中断. 最佳置换法 ...

  3. Tomcat手动指定jdk路径

    Windows系统: 修改bin下的setclasspath.bat,在开头处添加: rem set specific jdkset JAVA_HOME=%CATALINA_HOME%\jdk1.8. ...

  4. poj-1113

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31419   Accepted: 10619 Descriptio ...

  5. Restful Framework 初识

    目录 一.什么是RESTful 二.什么是API 三.RESTful API规范 四.基于Django实现API 五.基于Django Rest Framework框架实现 一. 什么是RESTful ...

  6. 部署Nginx

    部署Nginx #下载nginx wget http://nginx.org/download/nginx-1.12.2.tar.gz#安装依赖 yum install pcre-devel open ...

  7. Storm实战常见的问题

    该文档为实实在在的原创文档,转载请注明: http://blog.sina.com.cn/s/blog_8c243ea30101k0k1.html 类型 详细 备注 该文档是群里几个朋友在storm实 ...

  8. 三:Storm设计一个Topology用来统计单词的TopN的实例

    Storm的单词统计设计 一:Storm的wordCount和Hadoop的wordCount实例对比

  9. Redis安装+密码认证

    redis: 安装: $ wget http://download.redis.io/releases/redis-3.2.7.tar.gz $ tar xzf redis-3.2.7.tar.gz ...

  10. Linux(CentOS)下的JDK的安装和环境配置

    下载对应版本JDK,如jdk-6u45-linux-i586-rpm.bin添加执行权限:#chmod +x jdk-6u45-linux-i586-rpm.bin安装:#./jdk-6u45-lin ...