How to delete Desktop shortcuts after the android program is uninstalled

Source: Internet
Author: User

My application will create a shortcut on the desktop when it is used for the first time. The code for creating a shortcut is as follows: my application will create a shortcut on the desktop when it is used for the first time. The code for creating a shortcut is as follows: my application will create a shortcut on the desktop when it is used for the first time. The code for creating a shortcut is as follows: when my program is used for the first time, a shortcut will be created on the desktop. The Code is as follows:

Java code
  1. Intent intent = new intent ();
  2. Intent. setclass (this, splashactivity. Class );
  3. Intent addshortcut = new intent (action_add_shortcut );
  4. Parcelable icon = intent. Reset cuticonresource. fromcontext (this,
  5. R. drawable. Icon );
  6. Addshortcut. putextra (intent. extra_shortcut_name, getstring (R. String. app_name ));
  7. Addshortcut. putextra (intent. extra_shortcut_intent, intent );
  8. Addshortcut. putextra ("DUPLICATE", 0 );
  9. Addshortcut. putextra (intent. extra_shortcut_icon_resource, icon );
  10. Sendbroadcast (addshortcut );

However, when the program is uninstalled, it does not delete the shortcuts on the desktop at the same time. This problem happened to me for a long time yesterday and is finally solved today. The solution is as follows:

Java code

  1. Intent intent = new intent ();
  2. Intent. setclass (this, splashactivity. Class );
  3. Intent. setaction ("android. Intent. Action. Main ");
  4. Intent. addcategory ("android. Intent. Category. launcher ");
  5. Intent addshortcut = new intent (action_add_shortcut );
  6. Parcelable icon = intent. Reset cuticonresource. fromcontext (this,
  7. R. drawable. Icon );
  8. Addshortcut. putextra (intent. extra_shortcut_name, getstring (R. String. app_name ));
  9. Addshortcut. putextra (intent. extra_shortcut_intent, intent );
  10. Addshortcut. putextra ("DUPLICATE", 0 );
  11. Addshortcut. putextra (intent. extra_shortcut_icon_resource, icon );
  12. Sendbroadcast (addshortcut );


However, when the program is uninstalled, it does not delete the shortcuts on the desktop at the same time. This problem happened to me for a long time yesterday and is finally solved today. The solution is as follows: that is, adding two filter attributes to intent.

Intent. setaction ("android. Intent. Action. Main ");

Intent. addcategory ("android. Intent. Category. launcher ");

In this way, the desktop icon will be bound to my application. After the application is uninstalled, the system will automatically delete the icon at the same time.

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.