Public class shortcututil {</P> <p>/** <br/> * Create a shortcut <br/> * @ Param context <br/> * /<br/> Public static void createshortcut (context, class <?> Target) {<br/> // <uses-Permission Android: Name = "com. android. launcher. permission. install_shortcut "/> <br/> intent = new intent (" com. android. launcher. action. install_shortcut "); <br/> intent. putextra (intent. extra_shortcut_icon_resource, intent. using cuticonresource. fromcontext (context, R. drawable. icon); <br/> intent. putextra (intent. extra_shortcut_name, context. getstring (R. string. app_name); <br /> Intent. putextra ("DUPLICATE", false); <br/> intent sintent = new intent (intent. action_main); <br/> sintent. addcategory (intent. category_launcher); // after adding action and category, <SPAN class = 'wp _ keywordlink '> the shortcut is automatically uninstalled only when the program is uninstalled </span> <br/> sintent. setclass (context, target); <br/> intent. putextra (intent. extra_shortcut_intent, sintent); <br/> context. sendbroadcast (intent); <br/>}</P> <p>/** <br/> * determines whether a shortcut exists on the desktop. <Br/> * @ return <br/> */<br/> Public static Boolean hasshortcut (context) {<br/> final contentresolver Cr = context. getcontentresolver (); <br/> final string authority = "com. android. launcher. settings "; <br/> final URI content_uri = Uri. parse ("content: //" + authority + "/favorites? Policy = true "); <br/> // <uses-Permission Android: Name =" com. android. launcher. permission. read_settings "/> <br/> cursor c = CR. query (content_uri, new string [] {"intent"}, null); <br/> If (C = NULL) {<br/> // note: In versions 2.1update and 2.2, the real machine cannot access COM. android. launcher. settings, 2.1update1 simulators can be <br/> // error/activitythread (1136): failed to find provider info for com. android. launcher. settings <br/> return false; <br/>}< br/> while (C. movetonext () {<br/> string intentstring = C. getstring (C. getcolumnindex ("intent"); <br/> If (intentstring = NULL) {<br/> continue; <br/>}< br/> string componentstring = getcomponentstring (intentstring); <br/> If (componentstring. startswith (context. getpackagename () {<br/> return true; <br/>}< br/> return false; <br/>}</P> <p> Private Static string getcomponentstring (string intentinfo) {<br/> // intent Info format: intent = # intent; action = android. intent. action. main; Category = android. intent. category. launcher; launchflags = 0x10200000; Component = com. allstar. tanzhi /. activities. startactivity; end <br/> int start = intentinfo. indexof ("component") + 9 + 1; <br/> int end = intentinfo. indexof (";", start); <br/> return intentinfo. substring (START, end); <br/>}