UNINSTALL_SHORTCUT
permission to your AndroidManifest.xml:
Full Screen
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
call the com.android.launcher.action.UNINSTALL_SHORTCUT action:
full source code:
Full Screen
public void addShortcut(){
this.mActivity.sendBroadcast(getShortcutIntent(1));
}
private Intent getShortcutIntent(int type){
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(this.mActivity.getPackageName(), "com.lang.quotes.MainActivity");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// 这里必须为Intent设置一个action,可以任意(但安装和卸载时该参数必须一致)
shortcutIntent.setAction(Const.G_SHORTCUT_ACTION);
Intent localIntent = new Intent();
localIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
localIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, this.mActivity.getResources().getString(R.string.app_name));
//不允许重复创建
localIntent.putExtra("duplicate", false);
if( type == 1){
localIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this.mActivity, R.drawable.icon));
localIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
}
if( type == 2){
Log.i(Const.LOG_TMP, "removeShorcut 2");
localIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
}
return localIntent;
}
private void removeShorcut(){
Log.i(Const.LOG_TMP, "removeShorcut");
this.mActivity.sendBroadcast(getShortcutIntent(2));
}
http://codinggeek.org/2011/01/31/android-home-screen-shortcuts-part-iii-remove-shortcuts/