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
- Intent intent = new intent ();
- Intent. setclass (this, splashactivity. Class );
- Intent addshortcut = new intent (action_add_shortcut );
- Parcelable icon = intent. Reset cuticonresource. fromcontext (this,
- R. drawable. Icon );
- Addshortcut. putextra (intent. extra_shortcut_name, getstring (R. String. app_name ));
- Addshortcut. putextra (intent. extra_shortcut_intent, intent );
- Addshortcut. putextra ("DUPLICATE", 0 );
- Addshortcut. putextra (intent. extra_shortcut_icon_resource, icon );
- 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
- Intent intent = new intent ();
- Intent. setclass (this, splashactivity. Class );
- Intent. setaction ("android. Intent. Action. Main ");
- Intent. addcategory ("android. Intent. Category. launcher ");
- Intent addshortcut = new intent (action_add_shortcut );
- Parcelable icon = intent. Reset cuticonresource. fromcontext (this,
- R. drawable. Icon );
- Addshortcut. putextra (intent. extra_shortcut_name, getstring (R. String. app_name ));
- Addshortcut. putextra (intent. extra_shortcut_intent, intent );
- Addshortcut. putextra ("DUPLICATE", 0 );
- Addshortcut. putextra (intent. extra_shortcut_icon_resource, icon );
- 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.