2011.09.09(2)——— android 桌面添加快捷方式
参考:
http://www.apkbus.com/android-5728-1-1.html
添加快捷方式:
private void installShortCut(){
Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
// 是否可以有多个快捷方式的副本,参数如果是true就可以生成多个快捷方式,如果是false就不会重复添加
shortcutIntent.putExtra("duplicate", false);
Intent mainIntent = new Intent(Intent.ACTION_MAIN);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
// 要删除的应用程序的ComponentName,即应用程序包名+activity的名字
//intent2.setComponent(new ComponentName(this.getPackageName(), this.getPackageName() + ".MainActivity"));
mainIntent.setClass(this, this.getClass());
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mainIntent);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
sendBroadcast(shortcutIntent);
} sendBroadcast(shortcutIntent);
权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
总不能每次进入应用 都添加一次快捷方式 所以 需要判断一下快捷方式是否已经存在
private boolean hasShortCut() {
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(Uri.parse("content://com.android.launcher.settings/favorites?notify=true"), null, "title=?",
new String[] {getString(R.string.app_name)}, null);
if (cursor != null && cursor.moveToFirst()) {
cursor.close();
return true;
}
return false;
}
查询权限:
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
删除快捷方式:
private void uninstallShortcut(){
System.out.println("11");
Intent intent = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setClass(this, this.getClass()));
sendBroadcast(intent);
}
权限:
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
分享到:
相关推荐
2. 冷——热 3. 早——晚 4. 长——短 5. 甜——苦 6. 慢——快 7. 黑——白 8. 近——远 9. 前——后 10. 冷淡——热情 11. 黑暗——光明 12. 南——北 13. 低——高 14. 闲——忙 15. 开——关 16. 哭——笑 17. ...
16.C#应用程序开发全程演练——从灵感到实现
在Android操作系统中,桌面快捷方式是一种便捷的方式,允许用户快速访问他们经常使用的应用程序、联系人、设置或者其他功能。本文将详细讲解如何创建和删除Android桌面快捷方式,以及它们的工作原理。 **一、创建...
python项目——Word助手.zip python项目——Word助手.zip python项目——Word助手.zip python项目——Word助手.zip python项目——Word助手.zip python项目——Word助手.zip python项目——Word助手.zip python项目...
2,jdk-170.tar.gz ——————————JDK1.7deb包 3,switch_java.sh -------------------------java其它版本切换 4,check_java.sh———————————版本核对 注意:使用命令接口切换时,需要将自己配置的...
Android中文翻译组——Android中文API合集(4).chm
基于因子分析的我国A股上市...争力评价——以医药企业为例_张澳.caj
python项目——RCQ读者书库.zip python项目——RCQ读者书库.zip python项目——RCQ读者书库.zip python项目——RCQ读者书库.zip python项目——RCQ读者书库.zip python项目——RCQ读者书库.zip python项目——RCQ...
6.蘑菇该奖给谁2——小学生ppt学习课件
C语言项目——企业员工管理系统.zip C语言项目——企业员工管理系统.zip C语言项目——企业员工管理系统.zip C语言项目——企业员工管理系统.zip C语言项目——企业员工管理系统.zip C语言项目——企业员工管理系统....
基于IntraWeb的数据表格的多选实现 既可以单条操作,也可以多选操作。 delphi源代码。 BS开发Web网站开发,不需要安装服务器,Apache和IIS都不需要,自带企业级服务器。...————————————————
Android support.v7包
微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+...
2. 给……买 —— buy...for 3. 去看电影 —— go to the cinema 4. a pair of jeans —— 一条牛仔裤 5. a girl named Mary —— 一个名叫Mary的女孩 6. next Sunday —— 下周日 7. 同时 —— at the same time ...
5.苹果里的五角星——小学生ppt学习课件
大创项目——区块链追溯系统.zip大创项目——区块链追溯系统.zip大创项目——区块链追溯系统.zip大创项目——区块链追溯系统.zip大创项目——区块链追溯系统.zip大创项目——区块链追溯系统.zip大创项目——区块链...
2. **数据绑定和数据处理**:DevExpress控件高度支持数据绑定,能够无缝连接到各种数据源。源代码会展示数据提供者和适配器的实现,以及如何高效地检索和操作数据。 3. **布局和设计**:DevExpress的控件设计精美,...
Android开发者指南(2) —— aapt - 农民伯伯 - 博客园.mht351.20 KB Android开发者指南(3) —— Other Tools - 农民伯伯 - 博客园.mht362.93 KB Android开发者指南(4) —— Application Fundamentals - 农民伯伯 - ...
可行性研究报告(GB8567——88).doc 开发进度月报(GB8567——88).doc 操作手册(GB8567——88).doc 数据库设计说明书(GB8567——88).doc 数据要求说明书(GB8567——88).doc 文件给制实施规定的实例.doc...