Step-by-Step android development: Create an APP desktop shortcut
Zookeeper
I have referenced more than N documents on the Internet, and finally found that it is more reliable to write, so I will not repeat the creation of shortcuts.
// Create a shortcut
Private void addShortcut (){
Intent shortcut = new Intent ("com. android. launcher. action. INSTALL_SHORTCUT"); // keep the default value
// Shortcut name
Shortcut. putExtra (Intent. EXTRA_SHORTCUT_NAME, getString (R. string. app_name); // keep the default value
Repeated cut. putExtra ("duplicate", false); // repeated creation is not allowed.
Intent intent = new Intent (this, HomeActivity. class); // HomeActivity. class is the name of the activity that my program loads for the first time.
Intent. setAction ("com. figo. activity. home"); // This is the specific path of home.
Shortcut. putExtra (Intent. EXTRA_SHORTCUT_INTENT, intent );
// Displayed icon
Parcelable icon = Intent. javascuticonresource. fromContext (this, R. drawable. ic_launcher );
Shortcut. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE, icon );
SendBroadcast (broadcast cut); // Broadcast
}
// Delete shortcuts
Private void delemedicut (){
Intent shortcut = new Intent ("com. android. launcher. action. UNINSTALL_SHORTCUT ");
// Shortcut name
Shortcut. putExtra (Intent. EXTRA_SHORTCUT_NAME, getString (R. string. app_name ));
// The intent here must be consistent with the intent settings at the time of creation
Intent intent = new Intent (this, HomeActivity. class );
Intent. setAction ("com. figo. activity. home ");
Shortcut. putExtra (Intent. EXTRA_SHORTCUT_INTENT, intent );
SendBroadcast (shortcut );
}
Configuration File AndroidManifest. xml
Add Permissions
Add intent-filter
Android: name = "com. figo. activity. HomeActivity"
Android: launchMode = "singleTask"
Android: screenOrientation = "portrait"
Android: theme = "@ style/Theme. NoTitleBar"
Android: windowSoftInputMode = "adjustPan">