Create a shortcut for Android

Source: Internet
Author: User

Xml Code
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>

In your project list, the following code indicates that the activity is the activity started by the application. The system automatically creates a shortcut. When you use some applications, it sometimes allows you to create shortcuts such as the UC browser. How does this happen? In fact, it is also very simple. Only:
Java code
/**
* What do you want to do with the two lines of code?
*/
Uri uri = Uri. parse ("tel: 0800000123 ");
Intent myIntent = new Intent (Intent. ACTION_DIAL, uri );

Intent shortcut = new Intent ("com. android. launcher. action. INSTALL_SHORTCUT ");
 
Parcelable icon = Intent. Specify cuticonresource.
FromContext (this, R. drawable. beach); // gets the shortcut key icon
Shortcut cut. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE, icon); // shortcut icon
 
// Shortcut. putExtra (Intent. EXTRA_SHORTCUT_ICON, R. drawable. beach); // you can replace the above two lines of code.
Shortcut. putExtra (Intent. EXTRA_SHORTCUT_NAME, "shortcut"); // the title of the shortcut
Shortcut cut. putExtra (Intent. EXTRA_SHORTCUT_INTENT, myIntent); // shortcut action
 
SendBroadcast (shortcut cut); // you can also tell the system that you have created a shortcut


If you want to add an entry in the create shortcuts bar, for example


 
 

You only need to add the following content to the configuration file: (you need to create an activity, NoneShortcut)
Xml Code
<Activity android: name = ". NoneShortcut" android: icon = "@ drawable/photo6" android: label = "Haha">
<Intent-filter>
<Action android: name = "android. intent. action. CREATE_SHORTCUT"/>
</Intent-filter>
</Activity>

This article is from sunney2012"
 

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.