Android desktop shortcut add Delete update automatically run

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.