Android编程之创建桌面快捷方式
来源:互联网 发布:linux安装eclipse 编辑:程序博客网 时间:2024/05/20 11:34
在我们安装应用程序的时候,喜欢把常用的软件在桌面上有个快捷方式,那么我们可以在自己的程序中帮用户实现这一点,在用户第一次运行的时候,创建一个快捷方式在桌面上。这里,你也可以给用户个选择,是否需要创建快捷方式。
以下是创建快捷方式的代码:
/** * 创建桌面快捷方式 */private void addShortcut() {Intent intent = new Intent(Intent.ACTION_MAIN);intent.addCategory(Intent.CATEGORY_LAUNCHER);String cls = new StringBuilder(String.valueOf(getPackageName())).append(".").append(getLocalClassName()).toString();ComponentName componentName = new ComponentName(getPackageName(), cls);intent.setComponent(componentName);Intent shortCut = new Intent();shortCut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);// 快捷方式的名称shortCut.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name));// 快捷方式的ICONIntent.ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);shortCut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);// 不允许重复创建shortCut.putExtra("duplicate", false);shortCut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");sendBroadcast(shortCut);}
为了保持一致,这里的图标和名字都采用在应用程序中建立的名字,当然,你也可以修改成其他名字和图标。(估计没人会这么干的。。。-_-|||)
最后,注意增加权限:<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
- Android编程之创建桌面快捷方式
- Android学习之程序创建桌面快捷方式
- android 创建桌面快捷方式
- Android 创建桌面快捷方式
- android创建桌面快捷方式
- Android 创建桌面快捷方式
- android 创建桌面快捷方式
- Android 创建桌面快捷方式
- Android创建桌面快捷方式
- android 创建桌面快捷方式
- Android 创建桌面快捷方式
- Android 创建桌面快捷方式
- Android 创建桌面快捷方式
- Android:桌面创建快捷方式
- Android创建桌面快捷方式
- android 创建桌面快捷方式
- Android创建桌面快捷方式
- android 创建桌面快捷方式
- 【Visual C++】游戏开发笔记三十 DirectX11 2D纹理映射知识全攻略
- Struts2配置文件讲解
- hdu 1297 Children’s Queue(递推+大数)
- 【javaWeb】div居中
- 调用系统短信页面
- Android编程之创建桌面快捷方式
- android学习之widget3
- 在WinForm上添加语音朗读功能
- 调用另一个Activity之1
- android dialog ——ProgressDialog 进度条对话框详解
- Linux shll中的$符号 -- 读取命令行参数
- ios:改变tableview的titleForHeaderInSection字体颜色设置
- Eclipse快捷键大全(转载)
- poj3130 && poj3335 半平面交