Android创建和删除桌面快捷方式
有同学方反馈创建快捷方式后,点击快捷方式后不能启动程序或者提示"未安装程序",貌似是新的rom在快捷方式这块做过修改(由于此文是11年5月所出,估计应该是2.0或2.1的rom),现已修正,HTC G11 2.3.5rom测试通过.
1,判断是否已经创建了快捷方式(在某些机型中需要判断)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
private boolean hasShortcut(){ boolean isInstallShortcut = false; final ContentResolver cr = activity.getContentResolver(); final String AUTHORITY ="com.android.launcher.settings"; Cursor c = cr.query(CONTENT_URI,new String[] {"title","iconResource" },"title=?", new String[] {mapViewActivity.getString(R.string.app_name).trim()}, null); if(c!=null && c.getCount()>0){ isInstallShortcut = true ; } return isInstallShortcut ; } |
2, 创建
|
1
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
/** * 为程序创建桌面快捷方式 */ private void addShortcut(){ Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); //快捷方式的名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); shortcut.putExtra("duplicate", false); //不允许重复创建 /****************************此方法已失效*************************/ //ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName()); //shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); /******************************end*******************************/ Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClassName(this, this.getClass().getName()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); //快捷方式的图标 ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); sendBroadcast(shortcut); } |
3, 删除
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<strong> /** * 删除程序的快捷方式 */ private void delShortcut(){ Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT"); //快捷方式的名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); String appClass = this.getPackageName() + "." +this.getLocalClassName(); ComponentName comp = new ComponentName(this.getPackageName(), appClass); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); sendBroadcast(shortcut); } </strong> |
3, 声明权限
在AndroidManifest.xml 文件中声明 创建和删除快捷方式时声明权限
|
1
2
|
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /> |
Android创建和删除桌面快捷方式的更多相关文章
- Python创建、删除桌面、启动组快捷方式的例子分享
一.Python创桌面建快捷方式的2个例子 例子一: 代码如下: import osimport pythoncomfrom win32com.shell import shell from w ...
- ubuntu创建文件夹桌面快捷方式
最近在使用dropbox,用来存储一些自己的markdown笔记和pdf文件.觉得放一个快捷方式在桌面上比较方便,但是lxde似乎没有直接创建桌面快捷方式的功能(或者是我没有找到),就上网查了一下,顺 ...
- Android 通过程序添加桌面快捷方式
原理:通过代码向 Launcher 中的广播接收者发送广播来创建快捷图标. 首先要声明的权限是: <!--添加图标的权限--> <uses-permission android:na ...
- Android创建或删除了文件,在电脑端查看的时候,却没有对应的变化,处理办法
在Android应用中,碰到一个问题,在代码中执行创建或者删除某个文件后,在系统的文件管理器中能够相应地看到文件的变化,但是插在电脑上查看的时候,却看不到改文件的变化.同时,当创建文件后,在系统中的某 ...
- Win10创建mysql8.0桌面快捷方式以及启动mysql.exe闪退问题
1.先找到mysql的bin目录,将Mysql.exe发送快捷方式到桌面. 2.然后右键选择属性,将目标后面添加上 -uroot -p 我的完整目标如下: E:\mysql-8.0.17-winx64 ...
- Android -- 创建桌面快捷方式
代码 /** * * 返回添加到桌 ...
- Ubuntu创建桌面快捷方式
默认情况下,ubuntu会将自动安装的软件快捷方式保存在/usr/share/applications目录下,如果我们要创建桌面快捷方式,只需要右键-复制-桌面 就Ok,如图: 上面的方法是通过系统自 ...
- ubuntu系统下创建软件桌面快捷方式
转自ubuntu系统下创建软件桌面快捷方式 默认情况下,ubuntu会将自动安装的软件快捷方式保存在/usr/share/applications目录下,如果我们要创建桌面快捷方式,只需要右键-复制- ...
- c#: 创建桌面快捷方式
App适配输出方式时发现问题,聊做备忘. 需要注意的是:不要直接引用Interop.IWshRuntimeLibrary.dll程序集,因为它可能是x86或x64的,倘若程序以Any CPU方式编译, ...
随机推荐
- python中的upper、lower、capitalize、title
upper()字符串中字母由小写变为大写 lower()字符串中字母由大写变为小写 capitalize()字符串中字母首字母大写其余小写 title()字符串中字母每个单词的首字母大写其余小写 举个 ...
- elk之[logstash-input-file]插件使用详解
https://www.cnblogs.com/xing901022/p/4805586.html http://www.cnblogs.com/xing901022/p/4802822.html ...
- js页面百分比缩放
<script> var docEl = document.documentElement, resizeEvt = 'orientationchange' in window ? 'or ...
- 字符串md5之后转成int类型, 方便数据库索引
function hashStringToInt($string){ $stringHash = substr(md5($string), 0, 8); return base_convert($st ...
- day36-常见内置模块五(collections、xml模块)
一.collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:namedtuple.deque.Counter ...
- Aop 基础
基础文献 https://blog.csdn.net/abcd898989/article/details/50809321 简单Demo配置 pom.xml <!-- AOP --> & ...
- VirtualBox配置
安装增强工具:http://mikemainguy.blogspot.jp/2015/03/installing-virtualbox-guest-additions.html 安装ssh:https ...
- putty登录显示IP
登陆服务器 cd vi .bashrc 在尾部加入如下代码 if [ "$SSH_CONNECTION" != '' -a "$TERM" != 'linux' ...
- 24_ajax请求_使用axios
前置说明: 1.React本身只关注页面,并不包含发送ajax请求的代码 2.前端应用需要通过ajax请求与后台进行交互(json数据) 3.React应用中需要集成第三方ajax库(或自己进行封装) ...
- Mysql 死锁分析学习
https://blog.csdn.net/aesop_wubo/article/details/8286215 * CREATE TABLE `user_item` ( * `id` BIGIN ...