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:
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:
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.
From: yinkai1205 Column