SoFunction
Updated on 2025-04-10

How to add desktop icons and automatically delete icons after uninstalling the program

1: Create the icon as follows
Copy the codeThe code is as follows:

Intent intent = new Intent();
(this, );
Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT);
Parcelable icon = (this,
);
(Intent.EXTRA_SHORTCUT_NAME, getString(.app_name));
(Intent.EXTRA_SHORTCUT_INTENT, intent);
("duplicate", 0);
(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
sendBroadcast(addShortcut);

2: Delete the icon as follows
Copy the codeThe code is as follows:

Intent intent = new Intent();
(this, );
("");
("");
Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT);
Parcelable icon = (this,
);
(Intent.EXTRA_SHORTCUT_NAME, getString(.app_name));
(Intent.EXTRA_SHORTCUT_INTENT, intent);
("duplicate", 0);
(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
sendBroadcast(addShortcut);
("");
("");

Two filtering properties are required