A lot of people have also written to create desktop shortcuts blog, but most of them only talk about how to use, in fact, the technology is very simple to use, but you use the next time you know?
The root cause is still unclear, so today I'll talk about the shortcut creation process.
Process:
Home button-"Click Add-" Pop Up a Dialog dialog box-"Dialog dialog box data, is a system level specifically used to find the activity startup---" Find out the data display can add shortcuts---"and then save the data, Exit dialog--" Desktop launcher operation--"complete
principle:
Viewing the source code, in fact, is called the Pickshortcut () method in the launcher, start pickactivity Check the required data, in pickactivity will check
Manifest.xml in the activity has no add intenttfilter, if found, will be switch-case select the item to return the message to Laucher,
Laucher in onresultactivity () do accept the returned data, start again a band return worthwhile activity to shortcutactivity, wait for shortcutactivity
Processing completes, returns information, calls Completeaddlivefolder ().
In fact, we have to do the main steps 2 and 5, step 2 in manifest.xml to the activity to add intentfileter, step 5, to the shortcut to add a
icon and name.
Code:
<activity android:name= "Shortcuttest" > <intent-filter> <action android:name= " Android.intent.action.CREATE_SHORTCUT "/> </intent-filter> </activity>
public class Shortcuttest extends activity{@Override protected void onCreate (Bundle savedinstances Tate) {//TODO auto-generated Method Stub super.oncreate (savedinstancestate); CreateShortcut (); } public void CreateShortcut () {Intent addshortcut; Determine if you need to add a shortcut if (Getintent (). Getaction (). Equals (Intent.action_create_shortcut)) { Addshortcut = new Intent (); The name of the shortcut Addshortcut.putextra (Intent.extra_shortcut_name, "My Shortcuts"); The picture shown parcelable icon = Shortcuticonresource.fromcontext (this, r.drawable.icon); Addshortcut.putextra (Intent.extra_shortcut_icon_resource, ICON); The shortcut activates the activity, needs to execute the Intent, and defines itself Addshortcut.putextra (intent.extrA_shortcut_intent, New INTENT ()); OK, Generate Setresult (RESULT_OK, addshortcut); }else{//Cancel Setresult (result_canceled); } } }
Understand the principle, will not forget how to add a shortcut