Add shortcuts to the desktop in Android Development

Source: Internet
Author: User

Add shortcuts to the desktop in Android Development

Add shortcuts to the desktop in Android Development

For an application that wishes to have more users, the user desktop can be said to be a must for all software. If a user builds a shortcut for the software on the mobile desktop, users will use the software more frequently. Therefore, all Android programs should allow users to add shortcuts to the desktop.

Add a software shortcut to the desktop in the program. You only need to perform the following three steps:

1. Create an Intent that adds shortcuts. The value of the Action attribute of the Intent should be com. android. launcher. action. INSTALLSHORTCUT ,.

2. Add the Extra attribute to the Intent to set the title, icon, and Startup Program of the shortcut.

3. Call the sendBroadcast () method to send a broadcast to add a shortcut.

Instance code:

/*** Add shortcuts to the desktop * @ author jph * Date: 2014.09.05 */public class AddShortcut extends Activity {Button btnAddShortCut; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. mian); btnaddmediacut = (Button) findViewById (R. id. btnAddShortCut); btnAddShortCut. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {// TODO Auto-generated method stub // create an intentintintent addSC = new Intent ("com. android. launcher. action. INSTALL_SHORTCUT "); // the title of the shortcut key String title = getResources (). getString (R. string. shotcut_title); // The shortcut key icon Parcelable icon = Intent. using cuticonresource. fromContext (AddShortcut. this, R. drawable. ic_launcher); // create and click the shortcut key to start the program's IntentIntent launcherIntent = new Intent (AddShortcut. this, AddShortcut. class); // set the title of the shortcut key addSC. putExtra (Intent. EXTRA_SHORTCUT_NAME, title); // set the shortcut key icon addSC. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE, icon); // set the program addSC started by clicking this shortcut key. putExtra (Intent. EXTRA_SHORTCUT_INTENT, launcherIntent); // broadcast sendBroadcast (addSC );}});}}

Finally, create a shortcut for the application to add permissions:

 
 

Program running:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.