Automatically create shortcuts when Android opens apps

Source: Internet
Author: User

Today in the use of 360 mobile phone assistant, found that it will automatically create a quick start mode, it feels very interesting, so on the Internet Baidu Some methods, try, there is a way is quite good, I use for reference, first save, I also wrote a Test applet.

First, add the code in the mainactivity you want to launch the app into, and in the OnCreate () method, plus a method createshortcut ();

Then there is the implementation of the method:

private void CreateShortcut () {//TODO auto-generated Method Stub//create Shortcut Intent  addshortcut         = new Intent ("Com.android.launcher.action.INSTALL_SHORTCUT");        Duplicate creation of Addshortcut.putextra ("duplicate", false) is not allowed; <span><span class= "comment" > specifies that the current activity is a shortcut-initiated object:  such as  com.android.music.</span> musicbrowseractivity<span> </span></span>//<span><span class= "comment" > Note:  The second argument of the componentname must be preceded by a dot (.), or the shortcut cannot start the program </span><span></span></span>                  ComponentName comp = new ComponentName (This.getpackagename (), "."        + This.getlocalclassname ());        Addshortcut.putextra (intent.extra_shortcut_intent,new Intent (intent.action_main). SetComponent (comp)); Set icon for shortcut Shortcuticonresource icon = Intent.ShortcutIconResource.fromContext (This, r.drawable.ic_        Launcher); Addshortcut.putextra (INTENT.EXTRA_SHORTCUt_icon_resource, ICON);        Set the name of the shortcut  addshortcut.putextra (intent.extra_shortcut_name, getString (r.string.app_name)); Sendbroadcast (addshortcut);}
This, of course, has to add a permission to succeed: Add in Androidmanifest.xml

<uses-permission android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>
OK, now it's time to run the program!

Automatically create shortcuts when Android opens apps

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.