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