[Android Pro] 创建快捷方式,删除快捷方式,查询是否存在快捷方式
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] 创建快捷方式,删除快捷方式,查询是否存在快捷方式的更多相关文章
- Python创建、删除桌面、启动组快捷方式的例子分享
一.Python创桌面建快捷方式的2个例子 例子一: 代码如下: import osimport pythoncomfrom win32com.shell import shell from w ...
- [Android Pro] root用户删除文件提示:Operation not permitted
reference to : http://blog.csdn.net/evanbai/article/details/6187578 一些文件看上去可能一切正常,但当您尝试删除的时候,居然也会报错, ...
- Android创建和删除桌面快捷方式
有同学方反馈创建快捷方式后,点击快捷方式后不能启动程序或者提示"未安装程序",貌似是新的rom在快捷方式这块做过修改(由于此文是11年5月所出,估计应该是2.0或2.1的rom), ...
- 用注册表创建无法删除的IE快捷方式
代码如下: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{98745625-1234 ...
- android 多个shortCut快捷方式实现以及对58同城快捷方式的实现思路的研究
这几天,项目中有个新需求,需要按照模块添加不同的快捷方式到桌面上,从而方便用户的使用.特意进行了研究并分析了下58上面桌面快捷方式的实现. 首先多个shortcut的实现: <activity ...
- Elasticsearch 使用:创建、插入、查询、更新、删除
Elasticsearch 是一个开源的搜索引擎,建立在一个全文搜索引擎库 Apache Lucene™ 基础之上. Lucene 可能是目前存在的,不论开源还是私有的,拥有最先进,高性能和全功能搜索 ...
- 百度——LBS.云 v2.0——云存储的POI创建和删除--Android 源码
如有疑问请联系:QQ936467727 需要注意的几点问题: 1.密钥是http://lbsyun.baidu.com/apiconsole/key申请的,密钥类型是浏览器端 2.geotable_i ...
- Android创建或删除了文件,在电脑端查看的时候,却没有对应的变化,处理办法
在Android应用中,碰到一个问题,在代码中执行创建或者删除某个文件后,在系统的文件管理器中能够相应地看到文件的变化,但是插在电脑上查看的时候,却看不到改文件的变化.同时,当创建文件后,在系统中的某 ...
- MYSQL语句:创建、授权、查询、修改、统计分析等 一 用户的创建、权限设置、删除等
MYSQL语句:创建.授权.查询.修改.统计分析.. 一.用户的创建.权限设置.删除等 1.首先链接MySQL操作 连接格式:mysql -h 主机地址 -u 用户名 -p 用户密码 (注-u与roo ...
随机推荐
- [How to] UIScrollView的使用方法
1.简介 代码 延续前一个博客使用Xib来创建view,本文我们创建一个带有PageControlView的ScrollView的table的headView,如下图: 具有自动滚动: 具有拖拽完毕后 ...
- jQuery通过Ajax向PHP服务端发送请求并返回JSON数据
SON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写,同时也易于机器解析和生成.JSON在前后台交互的过程中发挥着相当出色的作用.请接着往下看教 ...
- leetcode 之Rotate List(18)
这题我的第一想法是用头插法,但实际上并不好做,因为每次都需要遍历最后一个.更简单的做法是将其连成环,找到相应的位置重新设头结点和尾结点.这过 有很多细节需要注意,比如K有可能是大于链表长度的,如何重新 ...
- 同步方法-java
除了同步代码块能实现同步执行外,同步方法也可以. 先看下同步代码块实现同步执行: public class Demo4 { public static void main(String[] args) ...
- django “如何”系列8:如何为模型提供初始化数据
当你第一次配置一个app的时候,有时候使用硬编码的数据去预填充你的数据库是非常有用的.这里有几个你可以让django自动创建这些数据的方法:你可以提供固定格式的初始化数据或者提供通过SQL初始化数据. ...
- 【python】配置文件
来源:http://developer.51cto.com/art/201003/189885.htm python 读写配置文件在实际应用中具有十分强大的功能,在实际的操作中也有相当简捷的操作方案, ...
- Disruptor 线程间共享数据无需竞争
队列的作用是缓冲 缓冲到 队列的空间里.. 线程间共享数据无需竞争 原文 地址 作者 Trisha 译者:李同杰 LMAX Disruptor 是一个开源的并发框架,并获得2011 Duke’ ...
- LeetCode解题报告—— Combination Sum & Combination Sum II & Multiply Strings
1. Combination Sum Given a set of candidate numbers (C) (without duplicates) and a target number (T) ...
- Monty Hall悖论
Monty Hall悖论又称为蒙提·霍尔悖论.三门问题.Monty Hall是上个世纪60年代,电视游戏节目“Let's Make a Deal”的主持人,这个悖论便是以他的名字来命名的.节目的规则是 ...
- Apache配置基于IP的虚拟主机 Apache virtual host configuration is based on the IP
Step 1: 检查是否开启 httpd-vhosts.conf apache/conf/httpd.conf文件 # Virtual hosts Include conf/extra/httpd-v ...