APPのショートカットをHOME-SCREENから(追加してから)削除しようとしています。ショートカットの追加は完全に機能しますが、以下のコードを使用して作成したショートカットを削除できません。
public void setupShortCut(boolean create) {
shortcutIntent = new Intent();
shortcutIntent.setClassName("com.abc.xyz", "XYZActivity");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
Intent intentShortcut = new Intent();
intentShortcut.putExtra("android.intent.extra.shortcut.INTENT", shortcutIntent);
intentShortcut.putExtra("android.intent.extra.shortcut.NAME", getResources().getString(R.string.app_name));
intentShortcut.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", icon);
if(create) {
intentShortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
} else {
intentShortcut.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
}
sendBroadcast(intentShortcut);
}
どこが間違っているのか教えてください。
編集1:
マニフェストファイルで許可が必要です。
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /