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 ...
随机推荐
- HTTP中Get与Post、ViewState 原理
Http是请求,响应的模型,服务器不会来读取浏览器的网页,只能够得到客户端提交过来的数据当用户点击提交,服务器就知道"提交回来了"(PostBack) Get与Post 设置for ...
- 为什么aspx这么“慢”
首先你要明白什么viewstate:由系统生成的一个隐藏域,用来进行页面状态保持的 里面存放着关于判断页面是否提交的Ispostback,和一些关于服务器控件的状态和数据: (说明下 ,ViewSta ...
- z-index使用以及失效的处理方法
1.一般z-index的使用是在有两个重叠的标签,在一定的情况下控制其中一个在另一个的上方出现. 2.z-index值越大就越是在上层.z-index:9999:z-index元素的position属 ...
- init.d文件夹
/etc/init.d 是 /etc/rc.d/init.d 的软链接(soft link). [root@asus ~]# ll /etc/init.d lrwxrwxrwx. 1 root roo ...
- 国内各大互联网公司UED(用户体验设计)团队博客介绍
UED是什么UED = user experience design,用户体验设计.UED的通常理解,就是“我们做的一切都是为了呈现在您眼前的页面”.UED团队包括:交互设计师(Interactio ...
- lucene解决全文检索word2003,word2007的办法
在上一篇文章中 ,lucene只能全文检索word2003,无法检索2007,并且只能加载部分内容,无法加载全文内容.为解决此问题,找到了如下方法 POI 读取word (word 2003 和 wo ...
- iis post 请求.html文件报405
其实本地文件默认是不允许post请求的,但是需要配置一下,配置如下: 我的iis版本是8.5 当然默认也是不能post请求 *.html或是*.json的的文件的,这个问题困 ...
- Matlab界面语言切换,自由显示中文或英文语言
Matlab界面语言切换,自由显示中文或英文语言分享给大家,Matlab是一款商业数学软件,广泛使用于算法的开发.数据发现和数值计算等.不同用户对Matlab显示的语言需求也不一样,一用户习惯使用中文 ...
- delphi xe5 android 开发实现手机打电话和发短信
转载自 http://www.raysoftware.cn/ 其实都可以通过intent和URI调用系统功能.Windows程序员可以理解成是ShellExecute.这个是万金油.可以有调用各种功 ...
- 数据采集服务提供商,ip提供商 里面有些不错的基础数据
http://user.qzone.qq.com/1649677458 这家公司的爬虫应该挺牛的 !@#!#!~#¥¥¥@@http://www.site-digger.com/