Recently, I have seen that other apps have the function of automatically adding desktop icons, and I want my apps to have such a function. below is the method I used during my exercises.CodeFor your reference.
Every interactive application has a launcher class in the project list file. In addition to prompting that the system activity is an entry function, a shortcut icon of the application is added to the Application List. This article describes how launcher generates and removes shortcuts through the self-registered installshortcutreceiver and uninstallshortcutreceiver, and analyzes the problem of generating shortcuts and removing shortcuts for external APK intent requests.
Add icon:
Intent intent = new intent ("com. Android. launcher. Action. install_shortcut ");
Intent. putextra (intent. extra_shortcut_name, getstring (R. String. app_name ));
// Whether there can be copies of multiple shortcuts. If the parameter is true, multiple shortcuts can be generated. If the parameter is false, duplicate shortcuts will not be added.
Intent. putextra ("DUPLICATE", false );
Intent intent2 = new intent (intent. action_main );
Intent2.addcategory (intent. category_launcher );
// Delete the applicationProgramIs the application package name + activity name.
Intent2.setcomponent (New componentname (this. getpackagename (), this. getpackagename () + ". Main "));
Intent. putextra (intent. extra_shortcut_intent, intent2 );
Intent. putextra (intent. extra_shortcut_icon_resource, intent. Reset cuticonresource. fromcontext (this,
R. drawable. Icon ));
Sendbroadcast (intent );
Permissions to be added:
<Uses-Permission Android: Name = "com. Android. launcher. Permission. install_shortcut"/>
Delete icon:
Intent intent = new intent ("com. Android. launcher. Action. uninstall_shortcut ");
Intent. putextra (intent. extra_shortcut_name, appname );
// Componentname of the application to be deleted, that is, application package name + activity name
Intent. putextra (intent. extra_shortcut_intent, new intent ()
. Setcomponent (New componentname (info. activityinfo. packagename,
Info. activityinfo. Name). setaction ("android. Intent. Action. Main "));
Sendbroadcast (intent );
Add the delete permission: <uses-Permission Android: Name = "com. Android. launcher. Permission. uninstall_shortcut"/>