Android Development Add shortcut to Desktop

Source: Internet
Author: User
Tags key string

Android Development Add shortcut to Desktop

For an app that wants to have more users, the user desktop can be a battleground for all software, and users will use the software more frequently if they set up a shortcut to the software on their mobile desktop. Therefore, all Android programs should allow users to add shortcuts to the software to the desktop.

In the program to add a shortcut to the desktop software, only the following three steps can be:

1. Create a intent that adds a shortcut to the intent the Action property value should be Com.android.launcher.action.INSTALLSHORTCUT.

2. set the title, icon, and shortcut of the shortcut to the program that starts with the intent plus extra property.

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

Instance code:

/** * Add shortcut to Desktop * @author JPH * date:2014.09.05 */public class Addshortcut extends Activity {Button btnaddshortcut; @Overri deprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.mian) btnaddshortcut= (Button) Findviewbyid (r.id.btnaddshortcut); Btnaddshortcut.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated method stub//Create a intentintent that adds a shortcut Addsc=new Intent ("Com.android.launcher.action.INSTALL_SHORTCUT");//The title of the shortcut key string Title=getresources (). GetString ( R.string.shotcut_title);//shortcut key icon parcelable icon=intent.shortcuticonresource.fromcontext (AddShortcut.this, R.drawable.ic_launcher);//Create a click shortcut key to start the program Intentintent launcherintent=new Intent (Addshortcut.this, Addshortcut.class );//Set the title of the shortcut Addsc.putextra (intent.extra_shortcut_name, title);//Set the icon for the shortcut Addsc.putextra (intent.extra_shortcut_ Icon_resource, icon);//Set Click this shortcut to start the program Addsc.putextra (intent.extra_shortcut_intent,launcherintent);//Send the system to add shortcut keysThe broadcast sendbroadcast (ADDSC);}});}} 

Finally add permissions for the application creation accelerator:

<!--specify permissions to add installation Shortcuts--><uses-permission android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/ >

Program run:



Android Development Add shortcut to Desktop

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.