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

Source: Internet
Author: User

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)

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.