Android代码添加快捷方式与删除快捷方式
2013-01-07 14:54
351 查看
添加桌面快捷方式代码如下:
其中,shortcut.putExtra("duplicate", false);设置是否可以重复添加在某些厂商的定制launcher上不起作用,可以重复添加,比如华为桌面。而在360桌面上就可以起作用。这点需要注意。
卸载桌面快捷方式代码如下:
这段代码在某些厂商的定制launcher上不起作用,无法卸载快捷方式,比如华为桌面。360桌面上测试可以使用。
需要在manifest文件中声明使用权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
/* *新加添加快捷方式代码 */ 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); //设置快捷方式图标 ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); //设置快捷方式启动入口 ComponentName comp = new ComponentName(this.getPackageName(), LanuchActivity.class.getName()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); //发送广播,添加快捷方式 sendBroadcast(shortcut);
其中,shortcut.putExtra("duplicate", false);设置是否可以重复添加在某些厂商的定制launcher上不起作用,可以重复添加,比如华为桌面。而在360桌面上就可以起作用。这点需要注意。
卸载桌面快捷方式代码如下:
//设置快捷方式名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); //设置快捷方式启动入口 ComponentName comp = new ComponentName(getPackageName(), LanuchActivity.class.getName()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); //发送卸载快捷方式的图标 sendBroadcast(shortcut);
这段代码在某些厂商的定制launcher上不起作用,无法卸载快捷方式,比如华为桌面。360桌面上测试可以使用。
需要在manifest文件中声明使用权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
相关文章推荐
- android程序桌面快捷方式的检测添加和删除
- android 添加和删除快捷方式
- Android应用程序快捷方式操作(添加,删除,判断是否存在)
- android添加删除桌面快捷方式
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android 添加删除应用快捷方式
- Android添加桌面快捷方式和删除桌面快捷方式
- [转] Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android编程添加快捷方式(Short)到手机桌面的方法(含添加,删除及查询)
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android应用程序添加、删除快捷方式
- android桌面快捷方式添加 删除 更新 自动运行
- 应23code群友:特写上我自己的代码:android程序快捷方式的创建与删除
- Android添加(创建)、删除及判断是否存在桌面快捷方式的方法
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android 添加和删除快捷方式
- Android 开发之系统应用Launcher详解,简单添加和删除快捷方式及常见问题
- Android Launcher开发(四)Launcher概述及简单添加和删除应用程序的快捷方式
- Android Launcher开发(四)Launcher概述及简单添加和删除应用程序的快捷方式
- android桌面快捷方式添加 删除 更新 自动运行