How to create shortcuts for apps in Android (your understanding)

Source: Internet
Author: User

How to create shortcuts for apps in Android (your understanding)
As shown in the figure, Android creates shortcuts in seven steps: Step 1: The launcher program of the Android system calls its pickcut () method to start the pickActivity Program (Application) of the system. Step 2: The pickActivity Program (Application) will call its CheckIntentFilter () method after it is started, find and list the applications that can create shortcuts in the system. As long as the third-party App registers with the <Intent-filter> tag (for more information about how to register the App, see the following code), it can be found and listed. Step 3: Call Choseitem () step 4: After completing step 3, The pickActivity Program (Application) returns the selected message to the system launcher through Intent; Step 5: after the launcher program obtains the message returned by pickActivity, it will know who created the shortcut. by calling the ProcessShortcut () method, it will start the Activity responsible for creating the shortcut in the third-party App, this Activity is the Activity we mentioned in the second step that is registered with the <Intent-filter> label. Step 6: the Activity that creates a shortcut in a third-party App will return the shortcut name, icon, and jump path to launcher through Intent. Part 7: launcher receives the returned message and calls it The ComPleteAddShortcut () method is used to create shortcuts and display them on the desktop. After analyzing the principles, what steps should be taken as a third-party developer? We only need to complete the following two steps, and the system will do other things for us: first, register with the <Intent-filter> tag <activity android: name = ". createmedicut "> <intent-filter> <action android: name =" android. intent. action. CREATE_SHORTCUT "/> </intent-filter> </activity> the" createconcut "is the name of the Activity responsible for creating shortcuts. Then, return the relevant data copy code to Launcher: public class createconcut extends Activity {/*** Description ** @ param savedInstanceState * @ see android. app. activity # onCreate (android. OS. bundle) */@ Override protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); if (getIntent (). getAction (). equals (Intent. ACTION_CREATE_SHORTCUT) {Intent _ returnIntent = new Intent (); _ returnIntent. putExtra (Intent. EXTRA_SHORTCUT_NAME, "csx"); // name of the shortcut key _ returnIntent. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE, // ico Intent of the shortcut key. using cuticonresource. fromContext (this, R. drawable. ic_launcher); _ returnIntent. putExtra (Intent. EXTRA_SHORTCUT_INTENT, new Intent (this, MainActivity. class); // jump to Intent setResult (RESULT_ OK, _ returnIntent); // send finish (); // close this Activity }}}

Related Article

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.