Code
/*** * Returns the intent added to the desktop shortcut: * * 1. Assign action= "Com.android.launcher.INSTALL_SHORTCUT" to intent * 2. Set the intent that is defined as intent.extra_shortcut_inent to the action that is consistent with the installation (must have) * * 3. Add Permissions: Com.android.launcher.permission.INSTALL_ SHORTCUT*/ PublicIntent getshortcuttodesktopintent (context context) {Intent Intent=NewIntent (); Intent.setclass (Context, Context.getclass ()); /*The following two sentences are used to remove the desktop shortcut while uninstalling the app*/Intent.setaction ("Android.intent.action.MAIN"); Intent.addcategory ("Android.intent.category.LAUNCHER"); Intent Shortcut=NewIntent ("Com.android.launcher.action.INSTALL_SHORTCUT"); //Rebuild not allowedShortcut.putextra ("Duplicate",false); //Set name//Shortcut.putextra (intent.extra_shortcut_name,context.getstring (R.string.app_name));Shortcut.putextra (Intent.extra_shortcut_name, "11111"); //Set iconShortcut.putextra (Intent.extra_shortcut_icon_resource, Intent.ShortcutIconResource.fromContext ( Context, r.drawable.youtube)); //Set Intent and shortcut Association programsShortcut.putextra (intent.extra_shortcut_intent, Intent); returnshortcut; }
Permissions
<android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>
Call
Public void Click1 (View v) { this. Getshortcuttodesktopintent (mainactivity. this); Sendbroadcast (intent); }
I'm the dividing line of the king of the Land Tiger.