Android Create desktop shortcut key shortcut

Source: Internet
Author: User

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


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.