为应用创建快捷方式目前有两种方法:
1. 程序启动时主动添加快捷方式到桌面------------>主动添加
2.长按桌面,弹出应用选择窗,拖动应用到桌面---------->被动添加
公用方法:
/**
* 返回添加到桌面快捷方式的Intent:
* 1.给Intent指定action="com.android.launcher.INSTALL_SHORTCUT"
* 2.给定义为Intent.EXTRA_SHORTCUT_INENT的Intent设置与安装时一致的action(必须要有)
* 3.添加权限:com.android.launcher.permission.INSTALL_SHORTCUT
*/
public static Intent getShortcutToDesktopIntent(Context context) {
Intent intent = new Intent();
intent.setClass(context, context.getClass());
/*以下两句是为了在卸载应用的时候同时删除桌面快捷方式*/
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 不允许重建
shortcut.putExtra("duplicate", false);
// 设置名字
sho