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方式编译, ...
随机推荐
- 《算法》第四章部分程序 part 11
▶ 书中第四章部分程序,包括在加上自己补充的代码,二分图的判定和染色 ● 二分图 1 //+------------------------------------------------------ ...
- ant 标签详解
Ant 开发 Ant的构建文件当开始一个新的项目时,首先应该编写Ant构建文件.构建文件定义了构建过程,并被团队开发中每个人使用.Ant构建文件默认命名为build.xml,也可以取其他的名字.只不过 ...
- Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]
ERROR - Context initialization failed org.springframework.beans.factory.parsing.BeanDefinitionParsin ...
- django之block extend标签
class ExtendsNode(Node): must_be_first = True context_key = 'extends_context' def __init__(self, nod ...
- <基础> PHP 数组操作
array_filter — 用回调函数过滤数组中的单元 ( 如果 callback 函数返回 true,则 array 数组的当前值会被包含在返回的结果数组中.数组的键名保留不变 ) array a ...
- JEECG 3.7.3 新春版本发布,企业级JAVA快速开发平台
JEECG 3.7.3新春版本发布 - 微云快速开发平台 导读 ⊙精美Echart报表 ⊙二维码生成功能 ⊙Online接口改造采用JWT机制 ⊙智能菜单搜索 ⊙代码生成器模板优 ...
- intellijIDEA Spring配置文件提示: File is included in 4 contexts
前提: 不影响编码,但是出现淡黄色的背景 解决办法: 打开Project Structure —> 选择Modules -> 选择Spring ->先点减号把之前的都删除掉 -> ...
- 分布式ID生成学习
唯一 && 趋势有序 数据库auto_increment,多个写库时,每个写库不同的初始值和相同的步长(A(0,2)B(1,2)) 缺点:非绝对递增,写库压力大 DB只保存序列最大值, ...
- Matplotlib中文乱码问题
一.找到并修改matplotlibrc文件 进入Python安装目录下的Lib\site-packages\matplotlib\mpl-data目录,用记事本打开matplotlibrc文件:找到f ...
- 转: 如何用手机访问电脑本地 localhost 网页或者服务器, 以调试web项目
最近开始转向移动开发方向,因此对于一个移动开发的前端来说,使用各种真机来进行自己网站或者系统的界面进行针对性的调试就显的尤为重要了. 因此,会经常通过电脑开启一个 wifi 来供手机进行连接,形成一个 ...