Android 通过程序添加桌面快捷方式
2014-04-24 14:45
639 查看
原理:通过代码向 Launcher 中的广播接收者发送广播来创建快捷图标。
首先要声明的权限是:
首先要声明的权限是:
<!--添加图标的权限--> <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
//创建用于发送广播的intent Intent broadcastIntent = new Intent(); // 指定动作名称 broadcastIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); // 指定快捷方式的图标 Parcelable icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher); broadcastIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); // 指定快捷方式的名称 broadcastIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式的名称"); // 指定快捷图标激活哪个activity Intent activityIntent = new Intent(); activityIntent.setAction(Intent.ACTION_MAIN); activityIntent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName component = new ComponentName(this, MyActivity.class); activityIntent.setComponent(component); broadcastIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, activityIntent); // 只创建一次快捷方式 broadcastIntent.putExtra("duplicate", false); sendBroadcast(broadcastIntent);
相关文章推荐
- 重复制造轮子之——字节数组写入文件
- Ubuntu10.04搭建MTK android编译环境
- Ubuntu 安装 MTK65XX平台编译环境(兼容展讯android环境)
- android检测软键盘是否弹起
- Android GridView 一行显示数据(包括图片和文本),解决的办法是计算数据占该行的宽度是多少
- 为Android GridView 设置行背景
- android 4.4最新官方源码下载
- android ndk环境搭建总结
- android string显示多样式字…
- android traceview性能调试
- android混淆配置
- Android利用系统广播---监听应用程…
- 在android工程中导入layoutlib.jar…
- android添加常驻图标到状态栏
- android fragment
- 【android】scaleType属性与ImagVi…
- Android系统设置
- android2.2系统自带drawable资源
- android listview addHe…
- [Android]添加admob后,使用ProGua…