Create shortcuts for applications and determine whether to create shortcuts (Android)

Source: Internet
Author: User
 define two functions first: 
Public void addshortcut () {intent addintent = new intent ("com. android. launcher. action. install_shortcut "); string mytitle = getresources (). getstring (R. string. app_name); parcelable icon = intent. using cuticonresource. fromcontext (this, R. drawable. APP); // set intent after clicking the shortcut operation // intent myintent = new intent (this, start. class); // whether to allow repeated addintent Creation. putextra ("DUPLICATE", false); intent = new intent (intent. acti On_main); intent. setflags (intent. flag_activity_reset_task_if_needed); intent. addflags (intent. flag_activity_launched_from_history); intent. addcategory (intent. category_launcher); intent. setclass (this, start. class); addintent. putextra (intent. extra_shortcut_name, mytitle); addintent. putextra (intent. extra_shortcut_icon, icon); addintent. putextra (intent. extra_shortcut_intent, intent); sendbroadcast (addinte NT);} public Boolean ifaddshortcut () {Boolean isinstallshortcut = false; Final contentresolver Cr = appstoreactivity. this. getcontentresolver (); final string authority = "com. android. launcher2.settings "; Final URI content_uri = Uri. parse ("content: //" + authority + "/favorites? Required y = true "); cursor c = Cr. Query (content_uri, new string [] {" title "," iconresource "}," Title =? ", New string [] {getstring (R. String. app_name)}, null); If (C! = NULL & C. getcount ()> 0) {isinstallshortcut = true;} return isinstallshortcut ;}

ThenProgramAt startup:

 
// Create a shortcut Boolean flag = ifaddshortcut (); // if you have already created a shortcut, you do not need to create if (flag = false) {addshortcut ();}

 

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.