下面是主要步骤及主要代码:
第一步:权限,创建与删除,需要加入权限
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
第二步:编写代码
public void deleteShortCut() {
String DROP_SHORTCUT_ACTION = "com.android.launcher.action.UNINSTALL_SHORTCUT";
Intent intent2 = new Intent(DROP_SHORTCUT_ACTION);
// 指定要删除的shortcut名称
intent2.putExtra(Intent.EXTRA_SHORTCUT_NAME, "sina1");
String appClass2 = getPackageName() + "." + getLocalClassName();
ComponentName component2 = new ComponentName(getPackageName(),
appClass2);
intent2.putExtra(
Intent.EXTRA_SHORTCUT_INTENT,
new Intent().setAction(Intent.ACTION_MAIN).setComponent(
component2));
sendBroadcast(intent2);
}
public void createShortCut() {