Android 向桌面添加快捷方式
2010-12-30 15:01
295 查看
有时候为了使用方便,需要在桌面上添加快捷方式,下面是两种添加快捷方式的方法:
1.
代码
shortcut.putExtra("duplicate", false); //表示的为不允许重复设置
此种代码,直接添加到桌面上,并且也在上图所示的地方显示,但是此需要添加下面的权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
1.
代码
private void addShortcut(){ Intent shortcut = new Intent("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 //注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序 // ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName()); // shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this,ShortcutTest.class)); //快捷方式的图标 ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); sendBroadcast(shortcut); }
shortcut.putExtra("duplicate", false); //表示的为不允许重复设置
此种代码,直接添加到桌面上,并且也在上图所示的地方显示,但是此需要添加下面的权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
相关文章推荐
- android应用添加桌面快捷方式
- Android为应用在桌面添加一个快捷方式
- android桌面添加快捷方式之判断是否存在无效
- Android添加快捷方式(Short)到手机桌面
- Android添加快捷方式(Short)到手机桌面
- Android 通过程序添加桌面快捷方式
- [Android开发实战]Android添加快捷方式到桌面的两种方式
- Android开发之向桌面添加快捷方式
- Android中为你的应用程序添加桌面快捷方式
- 老外写的在桌面添加快捷方式(DELPHI XE5 ANDROID)
- Android添加快捷方式(Short)到手机桌面
- Android 开机自动运行和添加删除桌面快捷方式
- android添加删除桌面快捷方式
- Android 添加和删除桌面快捷方式
- Android 向桌面添加快捷方式
- Android开发被添加到桌面快捷方式
- Android向桌面添加快捷方式,使其指向特定的(URL)网页
- Android向桌面添加快捷方式,使其指向特定的网页
- android添加删除桌面快捷方式
- Android添加快捷方式(Shortcut)到手机桌面