Android adds shortcuts to the desktop

Source: Internet
Author: User

Sometimes you need to add shortcuts on the desktop for ease of use. The following are two ways to add shortcuts:

1.

 

Code

  Void  Setshortcut (){

Intent addshortcut = New Intent ();
// Set the shortcut name
Addshortcut. putextra (intent. extra_shortcut_name, " Quick exercise " );
// Create a shortcut icon
Parcelable icon = Intent. Reset cuticonresource. fromcontext (
Shortcuttest. This , R. drawable. Icon );
// Add shortcut icon
Addshortcut. putextra (intent. extra_shortcut_icon_resource, icon );
// Build intent for quick execution
Intent mailto = New Intent ( This , Shortcuttest. Class );
// Add a shortcut intent
Addshortcut. putextra (intent. extra_shortcut_intent, mailto );
// Normal
Setresult (result_ OK, addmediacut );

}

 

 

Pass the aboveCodeYou can onlyProgramAdd in startup. You cannot add it to events. You have no idea what it is, and you have not studied it carefully. Please let me know! In addition, it is not directly added to the desktop, but to the Add shortcut window,

 

2.

 

Code

 Private     Void  Addshortcut (){
Intent shortcut = New Intent ( " Com. Android. launcher. Action. install_shortcut " );

// Shortcut name
Shortcut. putextra (intent. extra_shortcut_name, getstring (R. String. app_name ));
// Shortcut. putextra ("DUPLICATE", false ); // Repeated creation is not allowed

// Specifies the object that the current activity is started as a shortcut, for example, Com. Everest. Video. videoplayer.
// Note: The second parameter of componentname must contain the dot (.). Otherwise, the corresponding program cannot be started in the shortcut mode.
// Componentname comp = new componentname (this. getpackagename (), "." + this. getlocalclassname ());

// Shortcut. putextra (intent. extra_shortcut_intent, new intent (intent. action_main). setcomponent (COMP ));
Shortcut. putextra (intent. extra_shortcut_intent, New Intent ( This , Shortcuttest. Class ));

// Shortcut icon
Shortcuticonresource iconres = Intent. Reset cuticonresource. fromcontext ( This , R. drawable. Icon );
Shortcut. putextra (intent. extra_shortcut_icon_resource, iconres );

Sendbroadcast (shortcut );
}

Repeated cut. putextra ("DUPLICATE", false); // indicates that repeated settings are not allowed.

This code is directly added to the desktop and displayed in the shown area. However, you need to add the following permissions:

 

<Uses-Permission Android: Name = "com. Android. launcher. Permission. install_shortcut"/>

 

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.