Step-by-Step android development: Create an APP desktop shortcut

Source: Internet
Author: User

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">



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.