android extra_shortcut_icon,Android Shortcut操作(一)
默认的Shortcut操作
默认安装后的应用(Launcher属性),图标都会出现在"抽屉面板"中,在里面长按并拖曳图标可以拖动到桌面,实现快捷方式的添加。
长按桌面的图标,"抽屉面板"的小箭头会变成一个垃圾箱的图标,然后将图标拖进去就删除了。
对Shortcut列表进行添加/删除操作
在默认桌面空白处长按,会弹出选择对话框,选择"Shortcut",找到要添加的应用快捷方式进行添加。
首先我们要将应用的选项添加到Shortcut列表里来,直接上代码:
/**
* 添加到Shortcut选项中(默认桌面上长按调出)
*
* 同时需要在manifest中为activity提供一个包含
* action="android.intent.action.CREATE_SHORTCUT"的intent-filter
*/
private void addShortcutToOptions(){
// 创建一个默认的Intent
Intent shortcut = new Intent();
//快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
//不允许重复创建
shortcut.putExtra("duplicate", false);
//指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer
//注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序
String appClass = this.getPackageName() + "." +this.getLocalClassName();
ComponentName comp = new ComponentName(this.getPackageName(), appClass);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newIntent(Intent.ACTION_MAIN).setComponent(comp));
// 下面的方法与上面的效果是一样的,另一种构建形式而已
// Intent respondIntent = new Intent(this, this.getClass());
// shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, respondIntent);
//快捷方式的图标
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
// 发送到消息队列
setResult(RESULT_OK, shortcut);
}
应用重装/卸载后会自动删除
直接对Shortcut进行添加/删除操作(通过代码)
要点:
1. 给Intent指定action="com.android.launcher.INSTALL_SHORTCUT"
2. 给定义为Intent.EXTRA_SHORTCUT_INENT的Intent设置与安装时一致的action(必须要有)
3. 在AndroidManifest.xml中添加权限:com.android.launcher.permission.INSTALL_SHORTCUT
/**
* 为程序创建桌面快捷方式
*
* 同时需要在manifest中设置以下权限:
*
*/
private void addShortcut(){
Intent shortcut = newIntent("com.android.launcher.action.INSTALL_SHORTCUT");
// 快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
// 不允许重复创建
shortcut.putExtra("duplicate", false);
// 指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer
// 这里必须为Intent设置一个action,可以任意(但安装和卸载时该参数必须一致)
String action = "com.android.action.test";
Intent respondIntent = new Intent(this, this.getClass());
respondIntent.setAction(action);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, respondIntent);
// 下面的方法与上面的效果是一样的,另一种构建形式而已
// 注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序
// String appClass = this.getPackageName() + "." + this.getLocalClassName();
// ComponentName comp = new ComponentName(this.getPackageName(), appClass);
// shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(action).setComponent(comp));
// 快捷方式的图标
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);
}
android extra_shortcut_icon,Android Shortcut操作(一)相关推荐
- android extra_shortcut_icon,Android自动创建shortcut
为当前Activity创建快捷方式 private void addShortCut(){ //添加action Intent shortcut = new Intent("com.andr ...
- android如何在底部显示四个按钮,[Android系列—] 四. 添加操作栏(Action Bar)
[Android系列-] 4. 添加操作栏(Action Bar) 前言 操作栏是最重要的设计元素之一,使用它来实现你的应用程序活动.通过提供多种用户界面功能, 使应用程序快速和其他的Andorid应 ...
- 非常详细的测试unity与android之间的通讯操作
非常详细的测试unity与android之间的通讯操作 博客分类: unity3dandroid 非常详细的测试unity与android之间的通讯操作 转载自 http://www.narkii.c ...
- android 开发使用adb操作sqlite
android 开发使用adb操作sqlite. 1.启动模拟器或连接android实体机 2.在命令行输入:adb shell 3.进入目录:data/data/应用程序包名/databases/ ...
- android中的数据库操作(SQLite)
android中的数据库操作 android中的应用开发很难避免不去使用数据库,这次就和大家聊聊android中的数据库操作. 一.android内的数据库的基础知识介绍 1.用了什么数据库 an ...
- Android开发--Wifi的操作
Android应用程序测试Wifi非常简单,只需要调用系统的Wifi服务即可对Wifi进行管理,但是由于模拟器中不能使用Wifi的功能,所以测试的操作需要在手机上运行,下面是实例代码: public ...
- Android Studio相见恨晚的操作锦集
作为一个Android开发者,最常使用的就是Android Studio了,我在这里声明Android Studio比Eclipse好用100倍,不服来辩.本文用于纪录Android Studio中相 ...
- Android控制WIFI相关操作
Android控制WIFI相关操作 在XML文件中添加权限: <uses-permission android:name="android.permission.ACCESS_WIFI ...
- android service 访问数据库,XE5 ANDROID通过webservice访问操作MSSQL数据库
XE5 ANDROID通过webservice访问操作MSSQL数据库 上接XE5 ANDROID平台 调用 webservice 一.服务端 在ro里添加函数(在impl上添加阿东connectio ...
最新文章
- 在ubuntu10.4安装snort ACID
- 制作win7+ubuntu +winPE+CDlinux多系统启动U盘
- mysql小计_使用SQL实现小计,合计以及排序_MySQL
- 怎么配置在谷歌和ie内核时使用不同的_重磅!微软竟然研发了谷歌内核的edge
- python 主函数 输入
- 选择、插入、冒泡排序
- 如何用libpng输出一个编辑后的png图片?
- Category:UITextField添加点击事件
- 华为服务器报错信息,厂商 push 不通排查指南
- commit分拆多个 git_git如何合并只有两个commit到一个?
- 【转】python编写规范——中标软件有限公司测试中心
- live555 rtsp直播卡顿马赛克优化
- 我为App做测试---搜狐新闻(1)
- 英语口语html5源码,5篇英语经典美文赏析,可以当口语练习素材哦
- Protobuf报错CHECK failed: GeneratedDatabase()->Add(encoded_file_descriptor, size):
- 对称矩阵的三对角分解(Lanzos分解算法)-MINRES算法预热
- Java~Java代理模式
- rabbitmq java 测试_RabbitMQ 简单测试
- Android三种模拟器介绍
- php案例:$_SERVER详解(图文并茂)