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: