Android 快捷方式
1. 需要权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />2. 判断是否创建
/**
* 判断快捷方式是否创建
* @param context
* @param name 快捷方式名称
* @return
*/
public static boolean hasShortcut(Context context, String name) {
boolean isInstallShortcut = false;
final ContentResolver cr = context.getContentResolver();
final String AUTHORITY = "com.android.launcher.settings";
final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/favorites?notify=true");
Cursor cursor = null;
try {
cursor = cr.query(CONTENT_URI, new String[] { "title",
"iconResource" }, "title=?", new String[] { name }, null);
if (cursor != null && cursor.getCount() > 0) {
isInstallShortcut = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
} return isInstallShortcut;
}
3. 创建快捷方式
/**
* 添加快捷方式
*/
public static void addShortcut(Activity activity, String name, int resourceId) { Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); // 快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
shortcut.putExtra("duplicate", false); // 不允许重复创建 // 指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer
// 注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序 /**************************** 此方法已失效 *************************/
//ComponentName comp = new ComponentName(activity.getPackageName(), "." + activity.getLocalClassName());
//shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); // 快捷方式的图标
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(activity, resourceId);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); // 添加要做的事情
Intent todo = new Intent(Intent.ACTION_MAIN);
todo.setClassName(activity, activity.getClass().getName());
todo.putExtra("test1", "test");
// 点击快捷方式 进行 todo 操作
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, todo); activity.sendBroadcast(shortcut); }
4.删除快捷方式
/**
* 删除快捷方式
*/
public static void delShortcut(Activity activity, String name) {
Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT"); // 快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
String appClass = activity.getPackageName() + "." +activity.getLocalClassName();
ComponentName comp = new ComponentName(activity.getPackageName(), appClass);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
activity.sendBroadcast(shortcut); }
Android 快捷方式的更多相关文章
- Android 快捷方式相关操作
尽管现在少数手机不支持快捷方式,但是仍然有大部分手机是支持的.创建快捷方式,可以减少用户在应用列表繁多的应用程序中查找应用的时间,快速进入应用:或是应用中的某个功能使用频率较高,创建快捷方式,可以快速 ...
- 【转】Android 快捷方式的创建
http://blog.csdn.net/lenmoyouzi/article/details/16939977 一.在日常开发中,我们经常会遇到这样的需求就是网桌面添加快捷方式:常见的快捷方式有两种 ...
- Android 快捷方式的创建与查询 快捷方式问题大全 获取快捷方式在Launcher数据库中的信息 Failed to find provider info for com.android.la
/** * 创建添加快捷方式 * 其中需要设置的有: * 1. 快捷方式的标题 * 2. 快捷方式的图标 * 3. 点击快捷方式后的跳转 */ public static void createSho ...
- 张高兴的 Xamarin.Forms 开发笔记:Android 快捷方式 Shortcut 应用
一.Shortcut 简介 Shortcut 是 Android 7.1 (API Level 25) 的新特性,类似于苹果的 3D Touch ,但并不是压力感应,只是一种长按菜单.Shortcut ...
- android仿微信红包动画、Kotlin综合应用、Xposed模块、炫酷下拉视觉、UC浏览器滑动动画等源码
Android精选源码 仿微信打开红包旋转动画 使用Kotlin编写的Android应用,内容你想象不到 Android手机上的免Root Android系统日志Viewer 一个能让微信 Mater ...
- 面向忙碌开发者的 Android
面向忙碌开发者的 Android passiontim 关注 2016.11.19 21:41* 字数 4013 阅读 2967评论 2喜欢 92 面向忙碌开发者的 Android 视频教程(Tuts ...
- [转] 给ubuntu中的软件设置desktop快捷方式(以android studio为例)
原文链接:http://www.cnblogs.com/kinyoung/p/4493472.html ubuntu的快捷方式都在/usr/share/applications/路径下有很多*.des ...
- 实现Android桌面的App快捷方式
本文描述的是,在App开发过程中,该如何实现App在Anroid桌面上生成App的快捷方式.主要分为两个步骤: 一,在AndroidManifest.xml中声明相关权限: <uses-perm ...
- 给ubuntu中的软件设置desktop快捷方式(以android studio为例)
ubuntu的快捷方式都在/usr/share/applications/路径下有很多*.desktop(eclipse的快捷方式也可以类似设置) 下面就建立我们的studio sudo gedit ...
随机推荐
- 利用php获取图片完整Exif信息类 获取图片详细完整信息类
<?php /** * @Author: TonyLevid * @Copyright: TonyLevid.com * @Name: Image Exif Class * @Version: ...
- Headfirst设计模式的C++实现——命令模式(Command)
先看如果不用命令模式的实现: light.h #ifndef _LIGHT_H_ #define _LIGHT_H #include <iostream> class LIGHT { pu ...
- Git---Git及GitHub使用笔记
一.远程项目获取(克隆) syntax: $ git clone <版本库的网址> $ git clone <版本库的网址> <本地目录名> example: $ ...
- tq --uboot使用
- Nand Flash命令- nand info nand erase nand read[.jffs2] addr off size .jffs代表ECC方式不同 nan ...
- 迷你版 smarty --模板引擎和解析
http://blog.ipodmp.com/archives/php-write-a-mini-smarty-template-engine/ 迷你版Smarty模板引擎目录结构如下: ① 要开发一 ...
- jquery中onclick内$(this)指向
jquery中onclick=”fn”中$(this)所代表的对象 js方法 function qiehuan(){ var src = $(this).attr(“data”); alert($(t ...
- python【第二十一篇】Django模板继承、分页、cookie验证
1.模板继承 母版master.html {% block title %}{% endblock %}2 {% block table-cont %}{% endblock %} 子板 {% ext ...
- Computer Talker with C# z
Using the Code Add a textbox named 'txtWords' to a form. Add a button named 'btnSpeak' to a form. Ad ...
- ios:如何将自己编写的软件放到真正的iPhone上运行(转)
想要将自己编写的软件放到真正的iPhone上去运行,首先你需要成为Apple Developer计划的成员.其次,你需要设置程序ID和认证书,在这之后你就可以在你指定的iPhone上运行你的程序了.下 ...
- Web应用的组件化(二)
管控平台 在上一篇中我们提到了组件化的大致思路,这一篇主要讲述在这么做之后,我们需要哪些外围手段去管控整个开发过程.从各种角度看,面对较大规模前端开发团队,都有必要建立这么一个开发阶段的协作平台. 在 ...