Add shortcuts <uses-Permission Android: Name = "com. Android. launcher. Permission. install_shortcut"/>
Intent shortcutintent = new intent ("com. Android. launcher. Action. install_shortcut ");
Shortcutintent. putextra (intent. extra_shortcut_name, getstring (R. String. app_name ));
Shortcutintent. putextra ("DUPLICATE", false );
Intent intent = new intent ();
Intent. setcomponent (New componentname (getpackagename (), mainactivity. Class. getname ()));
Shortcutintent. putextra (intent. extra_shortcut_intent, intent );
Shortcutintent. putextra (intent. extra_shortcut_icon_resource, intent. Export cuticonresource. fromcontext (this, R. drawable. Icon ));
Sendbroadcast (shortcutintent );
Public class bootreceiver extends broadcastreceiver {
Public void onreceive (context, intent ){
// Receive broadcast: The program runs after the system is started.
If (intent. getaction (). Equals ("android. Intent. Action. boot_completed ")){
Intent newintent = new intent (context, searchdemo. Class );
Newintent. setaction ("android. Intent. Action. Main ");
Newintent. addcategory ("android. Intent. Category. launcher ");
Newintent. setflags (intent. flag_activity_new_task );
Context. startactivity (newintent );
}
// Receive broadcast: after an application package is installed on the device, the new application is automatically started.
If (intent. getaction (). Equals ("android. Intent. Action. package_added ")){
String packagename = intent. getdatastring (). substring (8 );
System. Out. println ("---------------" + packagename );
Intent newintent = new intent ();
Newintent. setclassname (packagename, packagename + ". searchdemo ");
Newintent. setaction ("android. Intent. Action. Main ");
Newintent. addcategory ("android. Intent. Category. launcher ");
Newintent. setflags (intent. flag_activity_new_task );
Context. startactivity (newintent );
}
// Receive broadcast: An application package is deleted from the device. : The root permission is required.
<Uses-Permission Android: Name = "com. Android. launcher. Permission. uninstall_shortcut"/>
If (intent. getaction (). Equals ("android. Intent. Action. package_removed ")){
String action_uninstall_shortcut = "com. Android. launcher. Action. uninstall_shortcut ";
Intent intent3 = new intent (action_uninstall_shortcut );
Intent. putextra (intent. extra_shortcut_name, R. String. app_name );
// Componentname of the application to be deleted, that is, application package name + activity name
Componentname comp = new componentname ("Search", "searchdemo ");
Intent. putextra (intent. extra_shortcut_intent, new intent ()
. Setcomponent (COMP). setaction ("android. Intent. Action. Main "));
Context. sendbroadcast (intent );
}
}
For your security, please only open the URL with reliable source
From: http://hi.baidu.com/lfcomputer/blog/item/15c31a6649bb6a37ab184c9b.html