Let's start by looking at the principle of creating shortcuts for apps in Android:
As can be seen from the figure, Android roughly 7 steps to complete the creation of shortcuts:
The first step: The launcher program of the Android system calls its Pickshortcut () method to start the system's Pickactivity program (application);
The second step:pickactivity Program (application) will call its Checkintentfilter () method, go to the system to find the application can create shortcuts, and listed. As long as the third-party app with the <Intent-filter> tag of the corresponding registration (how to register please see the code below) can be found and listed;
The third step: call the Choseitem () method to choose Who to create the shortcut;
Fourth step: after completing the third step, the Pickactivity program (application) will return the selected message to the System launcher by intent;
Fifth step:after the launcher program obtains the message returned by pickactivity, it will know who created the shortcut, by calling the Processshortcut () method to start the third party app in charge of creating the shortcut AC Tivity, this activity is the activity that we mentioned in the second step to register with the <Intent-filter> tag;
Sixth: the activity in the third-party app that creates the shortcut will return the shortcut's name, icon, and click-through path to launcher via intent;
Seventh:Launcher receives the returned message after calling itself the Completeaddshortcut () method to complete the creation of the shortcut and display it on the desktop;
After analyzing the rationale, what steps should be taken as a third-party developer?
We just need to complete the following 2 steps to OK, the other things the system will do for us:
First: Register with the <Intent-filter> tag
<android:name= ". Creatshortcut "> <intent-filter> < android:name= "Android.intent.action.CREATE_SHORTCUT"/> </intent-filter></activity>
The "Creatshortcut" is the name of the activity that is responsible for creating the shortcut.
Then: return the relevant data to the launcher
Public classCreatshortcutextendsActivity {/*** Description * *@paramSavedinstancestate *@seeandroid.app.activity#oncreate (Android.os.Bundle)*/@Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub Super. OnCreate (savedinstancestate); if(Getintent (). Getaction (). Equals (Intent.action_create_shortcut)) {Intent _returnintent=NewIntent (); _returnintent.putextra (Intent.extra_shortcut_name,"CSX");//the name of the shortcut key_returnintent.putextra (Intent.extra_shortcut_icon_resource,//ico for shortcut keysIntent.ShortcutIconResource.fromContext ( This, R.drawable.ic_launcher)); _returnintent.putextra (Intent.extra_shortcut_intent,NewIntent ( This, mainactivity.class));//shortcut keys for jump IntentSetresult (RESULT_OK, _returnintent);//SendFinish ();//Close this activity } }}
Done!!! (There are some other methods on the Internet, but they are very complex and not good to use)
How to create shortcuts for apps in Android (your own understanding)