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. [New learn] 手势

    1.简介 我们经常会在设备上查看图片等, 也会经常将图片通过手指的捏合打开来缩小和方法图片.这就是ios中的手势功能在起作用. 那么手势好像也是一种touch事件,那和UIResponder中定义的t ...

  2. tornado write render redirect IP

    write 用法( self.flush() ) render (跳转指定网页)用法 redirect(跳转指定路由)用法 self.request.remote_ip 显示用户 IP 地址 less ...

  3. App推广

    一行业常见名词解释 开发商:也叫CP,即Content Provider内容提供商的英文首字母缩写. 发行商(运营商):即代理CP开发出来的产品. 渠道:拥有用户,能够进行流量分发的公司,即可成为渠道 ...

  4. Eclipse中部署ES源码运行

    https://stackoverflow.com/questions/40924671/how-to-build-elasticsearch-source-code-using-gradle Gra ...

  5. 服务器迁移到 Windows Servec 2008 R2 64 bit 和IIS 7问题记录

    近期公司把网站迁移到了新的环境,windows service 2008 64 bit 和IIS 7,问题有点多,对系统使用影响很多,也困扰了我几个星期,现在记录一些主要的注意点 1.组件权限 系统使 ...

  6. thinkphp+dwz完成的一个号码查询小系统

    基于网友的例子(http://www.thinkphp.cn/extend/450.html),改进完成一个电话号码查询管理系统.基于thinkphp+dwz完成的电话号码查询小系统,主要改进与功能如 ...

  7. hdu 1874 畅通工程(spfa 邻接矩阵 邻接表)

    题目链接 畅通工程,可以用dijkstra算法实现. 听说spfa很好用,来水一发 邻接矩阵实现: #include <stdio.h> #include <algorithm> ...

  8. shell脚本学习(三)

    shell echo命令 显示普通字符串: echo "I am cat_crazy.'" 注:这里的双引号可以省略 显示转义字符: 如果要输出引号,*号等需要转义才能输出,如下 ...

  9. Java 中List 集合索引遍历与迭代器遍历

    package yzhou.iterator; import java.util.ArrayList; import java.util.HashSet; import java.util.Itera ...

  10. FZU 2297 Number theory【线段树/单点更新/思维】

    Given a integers x = 1, you have to apply Q (Q ≤ 100000) operations: Multiply, Divide. Input First l ...