Android Apidemos Sample Parsing (app->launcher) shortcuts

Source: Internet
Author: User
Tags filter home screen

The Android operating system displays an activity for <intent-filter> with the following properties in the Application Manager (Launcher), which typically corresponds to an application's main task.

<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>

In addition, if the user wants to add a shortcut to the appliance's home screen, the app's icon can be launcher in the Android system, and it will automatically add a shortcut to the home screen for the application. The name and icon are the same as in launcher.

In addition to supporting shortcuts to applications (primary activity), Android can define shortcuts to any activity in application on the home screen.

For example, there is a function in your application users may often use, such as the map to query the address, under normal circumstances users need to start the main activity, may need to go through a few menu options or other ways to enter this function, the user may feel inconvenient, this is possible for this function in the home Screen creates a shortcut, and the user presses the shortcut directly into the function interface, even if the activity is not the main one.

Launcher shortcuts is a description of how to create a shortcut on home screen for a non-primary activity.

To implement this shortcut, you can do this in the following steps:

1. <intent-filter> add <action android:name= "Android.intent.action.CREATE_SHORTCUT" for activity that requires the creation of a shortcut > identifies this activity to support the addition of shortcuts on home screen. Launcher Shortcuts is an alias for Target Activity-alias,activity-alias, similar to an activity.

2. Add the appropriate user to add a shortcut code, generally in the activity of the OnCreate method for the activity installation shortcuts:

if (Intent.ACTION_CREATE_SHORTCUT.equals (ACTION)) {setupshortcut ();     
 Finish ();     
Return     
 ... private void Setupshortcut () {///I, set up the shortcut intent.     
 For this example, we simply create a intent that/would bring us directly back to the activity. A more typical implementation would the use of a//data Uri in order to display a more specific result,//or a cus     
          
 Tom action in order to//launch a specific operation.     
 Intent shortcutintent = new Intent (intent.action_main);     
 Shortcutintent.setclassname (this, This.getclass (). GetName ());     
          
 Shortcutintent.putextra (Extra_key, "Apidemos provided this shortcut");     
 Then, set up the container intent (the response to the caller) Intent Intent = new intent ();     
 Intent.putextra (Intent.extra_shortcut_intent, shortcutintent); Intent.putextra (Intent.extra_shortcut_name, getString (R. String.shortcut_name));     
 Parcelable Iconresource = Intent.ShortcutIconResource.fromContext (this, r.drawable.app_sample_code);     
          
 Intent.putextra (Intent.extra_shortcut_icon_resource, Iconresource);     
Now, return the result to the Launcher Setresult (RESULT_OK, intent); }

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.