1) Create
/**
* IsProgramCreate a desktop shortcut
*/
Private Void Addshortcut (){
Intent shortcut = New Intent ("com. Android. launcher. Action. install_shortcut ");
// Shortcut name
Shortcut. putextra (intent. extra_shortcut_name, getstring (R. String. app_name ));
Shortcut. putextra ("DUPLICATE ",False ); // Repeated creation is not allowed
// Specifies the object that the current activity is started as a shortcut, for example, Com. Everest. Video. videoplayer.
// Note: The second parameter of componentname must contain the dot (.). Otherwise, the corresponding program cannot be started in the shortcut mode.
Componentname comp = New Componentname ( This . Getpackagename (), "." + This . Getlocalclassname ());
Shortcut. putextra (intent. extra_shortcut_intent,New Intent (intent. action_main). setcomponent (COMP ));
// Shortcut icon
Export cuticonresource iconres = intent. Export cuticonresource. fromcontext ( This , R. drawable. Icon );
Shortcut. putextra (intent. extra_shortcut_icon_resource, iconres );
Sendbroadcast (shortcut );
}
2) Delete
/**
* Shortcut for deleting a program
*/
Private Void Delemedicut (){
Intent shortcut = New Intent ("com. Android. launcher. Action. uninstall_shortcut ");
// Shortcut name
Shortcut. putextra (intent. extra_shortcut_name, getstring (R. String. app_name ));
// Specifies the object that the current activity is started as a shortcut, for example, Com. Everest. Video. videoplayer.
// Note: The second parameter of componentname must be a complete Class Name (package name + class name). Otherwise, the shortcut cannot be deleted.
String appclass = This . Getpackagename () + "." + This . Getlocalclassname ();
Componentname comp = New Componentname ( This . Getpackagename (), appclass );
Shortcut. putextra (intent. extra_shortcut_intent, New Intent (intent. action_main). setcomponent (COMP ));
Sendbroadcast (shortcut );
}
3) Declare Permissions
Declare the permission when creating or deleting shortcuts in the androidmanifest. xml file.
<Uses-Permission Android: Name = "com. Android. launcher. Permission. install_shortcut"/>
<Uses-Permission Android: Name = "com. Android. launcher. Permission. uninstall_shortcut"/>
References: http://ypf3027.iteye.com/blog/807597