You can see a lot of apps that pop up after the first run and say what shortcuts have been created, so how did this thing come out?
It's simple, just a few words, write it down here, copy it.
Create a class first
1 Importandroid.app.Activity;2 Importandroid.content.Intent;3 Importandroid.os.Parcelable;4 5 /**6 * Created by Administrator on 2016/1/21.7 */8 Public classShortCut {9 Public Static voidCreateShortcut (Activity Act,intIconresid,intAppnameresid) {TenIntent Intent =NewIntent ("Com.android.launcher.action.INSTALL_SHORTCUT"); One //do not allow duplicate creation AIntent.putextra ("Duplicate",false); - //need a real name - Intent.putextra (intent.extra_shortcut_name,act.getstring (Appnameresid)); the //Quick Picture -parcelable icon =Intent.ShortcutIconResource.fromContext (Act.getapplicationcontext (), iconresid); - Intent.putextra (Intent.extra_shortcut_icon_resource, ICON); - //Click on the quick picture to run the program +Intent.putextra (Intent.extra_shortcut_intent,NewIntent (Act.getapplicationcontext (), Act.getclass ())); - //Send broadcast + Act.sendbroadcast (intent); A at } -}
The above code
First generate an Intent instance (implicit intent), and then put some values into intent to configure
Above is a 4 value to control the creation of the shortcut icon
1. Do you want to allow duplicate creation
2. Determine the name of the icon created
3. Determine the picture of the icon created
4. Set click on this shortcut icon to run the app
You can create a shortcut icon by invoking the static method of the class in the first activity while your app is running for the first time.
Finally, don't forget to add permissions
<uses-permission android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>
Android APK installation automatically creates a shortcut icon on the desktop