public void ShortCut(View view){
createDeskShortCut(this,getString(R.string.short_cut),R.drawable.ups_icon,"http://www.baidu.com");
createDeskShortCut(this,getString(R.string.short_cut2),R.drawable.ups_icont,"http://image.baidu.com/");
Toast.makeText(this, "创建完成", 1).show();
}
/**
* 创建快捷方式
*/
public void createDeskShortCut(Context context,String name,int iconRes,String url) { Log.i("Javen","------createShortCut--------");
//创建快捷方式的Intent
Intent shortcutIntent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
//不允许重复创建
shortcutIntent.putExtra("duplicate",false);
//需要现实的名称
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); //快捷图片
Parcelable icon = Intent.ShortcutIconResource.fromContext(
getApplicationContext(),iconRes); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,icon); // Intent intent = new Intent(getApplicationContext(),
// MainActivity.class);
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
//下面两个属性是为了当应用程序卸载时桌面 上的快捷方式会删除
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
//点击快捷图片,运行的程序主入口
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,intent);
//发送广播。OK
sendBroadcast(shortcutIntent);
}

当你卸装你的应用程序的时候你又会发现存在一个问题就是你的应用程序虽然卸载了,可是桌面上的快捷方式并未卸载。呵呵,其实你只要在你要设置对应启动进入的那个Intent加上这么下面的两个属性就是表明与你的应用绑定了。

           //下面两个属性是为了当应用程序卸载时桌面 上的快捷方式会删除
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");

千万别忘记在AndroidManifest.xml加上下面的这个权限:

  <uses-permissionandroid:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

04-26 13:00