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 ...
随机推荐
- Extjs发票管理系统
技术特点:Extjs框架,三层架构,Ajax,json 1.仿office2007菜单.介面美观大方,可动态更改皮肤保存至cookie. 2,json数据源与实体类的相互转换. 3.可下载桌面版登录方 ...
- CSS3 skew倾斜、rotate旋转动画
css3出现之前,我们实现一个对象的一组连续动画需要通过JavaScript或Jquery编写,脚本代码较为复杂: 若需要实现倾斜.旋转之类的动画难度将更高(我还没试过用JavaScript或Jque ...
- MySQL修改时区的方法小结
这篇文章主要介绍了MySQL修改时区的方法,总结分析了三种常见的MySQL时区修改技巧,包括命令行模式.配置文件方式及代码方式,需要的朋友可以参考下 方法一:通过mysql命令行模式下动态修改 1.1 ...
- WPF中增加Month Calendar月历控件
XAML代码:(这里使用了codeproject.com网站上的一个Dll,你可以在这里下载它:http://www.codeproject.com/cs/miscctrl/MonthCalendar ...
- (九)groupByKey,reduceByKey,sortByKey算子-Java&Python版Spark
groupByKey,reduceByKey,sortByKey算子 视频教程: 1.优酷 2. YouTube 1.groupByKey groupByKey是对每个key进行合并操作,但只生成一个 ...
- DM8168 编译filesystem步骤
在板子跑起来之前,需要先编译好8168的文件系统.前提是已经设置好板子的类型等参数,详见<DM8168环境搭建> 1.进入<DVR_RDK_BASE>/dvr_rdk目录 ma ...
- Python 全栈开发 -- 监控篇
如果你已经玩转了 Python 编程语言语法,肯定想用这些知识,开发一款应用程序,它可以是在网上,可以炫耀或出售,那就需要全栈式开发 Python.具体如何创建,部署和运行生产 Python Web ...
- Sectong日志分析
http://tech.uc.cn/?p=2866#comments http://blog.sectong.com/blog/hw_bigdata.html
- SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-007-以set方法注入<property>\p-namespace\util-space
一.注入简单属性 package soundsystem.properties; import org.springframework.beans.factory.annotation.Autowir ...
- Migrating from IntelliJ Projects
We might provide an automatic migration option in Android Studio in the future. For now, to migrat ...