Compared with iOS development and Windows Phone development, Android is open, and Android development is more flexible and can do a lot of things. Some may find that after some Android applications are installed and run for the first time, a shortcut will be created on the desktop. How is this done?
Otherwise, Android is especially open. In Android development, this requirement can be achieved by sending a broadcast.
The following is a encapsulated section.Code.
Public class shortcututil {public static void createshortcut (Activity Act, int iconresid, int appnameresid) {// COM. android. launcher. permission. install_shortcutintent shortcutintent = new intent ("com. android. launcher. action. install_shortcut "); // duplicate shortcutintent cannot be created. putextra ("DUPLICATE", false); // the actual name shortcutintent is required. putextra (intent. extra_shortcut_name, act. getstring (appnameresid); // saved image parcelable icon = intent. using cuticonresource. fromcontext (Act. getapplicationcontext (), iconresid); shortcutintent. putextra (intent. extra_shortcut_icon_resource, icon); // click the shortcut image to runProgramMain Entry shortcutintent. putextra (intent. Intent, new intent (Act. getapplicationcontext (), Act. getclass (); // send Broadcast Act. sendbroadcast (shortcutintent );}}
The code is relatively simple and will not be explained in detail.
Do not forget to add the following permissions; otherwise, no effect will be displayed.
<Uses-Permission Android: Name = "com. Android. launcher. Permission. install_shortcut"/>
<Uses-Permission Android: Name = "Com. Android. launcher. Permission. read_settings" />
In addition, this may be unfriendly. A better way is to prompt the user whether to create a desktop shortcut when running the program for the first time, so that the user can choose. The prompt is no longer displayed after the task is run again.
---------------------------------------------------------------------------
GL (arui319)
Http://blog.csdn.net/arui319
<This article can be reproduced, but please keep the above author information. Thank you.>
---------------------------------------------------------------------------