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. pxe+kickstart自动化安装

    什么是PXE? PXE(Pre-boot Execution Environment,预启动执行环境)是Intel公司开发的最新技术,工作于Client/Server模式.PXE是一种远程引导方式,要 ...

  2. beatfullsoup

    阅读目录 一 介绍 二 基本使用 三 遍历文档树 四 搜索文档树 五 修改文档树 六 总结 一 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通 ...

  3. numpy及scipy的使用

    numpy的使用 把list A转换为numpy 矩阵 np.array(A) np.array(A, 'int32') numpy加载txt文件里面的矩阵 matrix = np.loadtxt(t ...

  4. ofbiz 之minilang解析

    编写一个simple method 首先我们需要对输入参数进行验证 ,判断参数是否完整. 1. 验证 1.1. Login-required :这是一个simple-method的属性,对是否需要登陆 ...

  5. Python与SQLite日期时间函数的使法

    SQLite的时间函数跟Python的时间函数有些许差别,所以稍做记录,供自己以后查询. 网上有将SQLite官方WIKI内容翻译成中文的文章,大家有兴趣可以搜索一下,我这里单纯记录一下个人比较常用的 ...

  6. 17-7-24-react入门

    先说明下为什么说好每天一更,周五周六周日都没有更新.因为在周五的时候,上司主动找我谈了转正后的工资4-4.5K.本来想好是6K的,后来打听了一圈公司的小伙伴,都是5-5.5,我就把自己定到了5K.万万 ...

  7. 差分【bzoj3043】IncDec Sequence

    Description 给定一个长度为n的数列{a1,a2...an},每次可以选择一个区间[l,r],使这个区间内的数都加一或者都减一. 问至少需要多少次操作才能使数列中的所有数都一样,并求出在保证 ...

  8. Codeforces Round #278 (Div. 1) Strip (线段树 二分 RMQ DP)

    Strip time limit per test 1 second memory limit per test 256 megabytes input standard input output s ...

  9. Nginx日志统一格式

    统一格式如下:nginx.conf 纯文本: log_format main '$remote_addr - $remote_user [$time_local] "$request&quo ...

  10. 【BZOJ 1052】 1052: [HAOI2007]覆盖问题 (乱搞)

    1052: [HAOI2007]覆盖问题 Description 某人在山上种了N棵小树苗.冬天来了,温度急速下降,小树苗脆弱得不堪一击,于是树主人想用一些塑料薄 膜把这些小树遮盖起来,经过一番长久的 ...