[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 ...
随机推荐
- tomcat8特性
作者:Eilen,转载需注明.博客主页:http://www.cnblogs.com/Eilen/ 一.Apache Tomcat 8介绍 Apache Tomcat 8RC1版于前几日发布.它 经过 ...
- 关于Free的override不能省略的问题,切记,虚方法是可以被覆盖的方法。
- JavaScript如何判断变量是数组还是对象
编辑 方法一:通过判断变量的类型,并且变量的length属性(除了有一种例外是arguments对象–当给函数传参时数据存储的地方) var arr=[2,3,4]; var obj={"n ...
- vue之v-text渲染多值
其原理,是利用vue里的computed计算属性来做. 请看代码: <div id='app'> <div v-text="newUsers"></d ...
- ELK系列--实时日志分析系统ELK 部署与运行中的问题汇总
前记: 去年测试了ELK,今年测试了Storm,最终因为Storm需要过多开发介入而放弃,选择了ELK.感谢互联网上各路大神,目前总算是正常运行了. logstash+elasticsearch+ki ...
- magento批量上传产品
Step1:表格仔细检查无误后,将准备好的图片上传至 media/import中.如果使用专用的图片服务器,把图片上传到服务器上,当然表格中的图片地址要做相应的修改. Step2:然后,登陆Magen ...
- react native native module
React Native Native Modules,官方地址:https://facebook.github.io/react-native/docs/native-modules-android ...
- LOJ #6284. 数列分块入门 8-分块(区间查询等于一个数c的元素,并将这个区间的所有元素改为c)
#6284. 数列分块入门 8 内存限制:256 MiB时间限制:500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 2 题目描述 给出 ...
- Spring MVC源码——Root WebApplicationContext
目录 Spring MVC源码--Root WebApplicationContext 上下文层次结构 Root WebApplicationContext 初始化和销毁 ContextLoaderL ...
- NetworkManager概述
NetworkManager服务是管理和监控网络设置的守护进程,CentOS7更加注重使用NetworkManager服务来实现网络的配置和管理,CentOS7以前是通过network服务管理网络,以 ...