Create Desktop shortcuts for mobile apps, and create shortcuts for apps

Source: Internet
Author: User

Create Desktop shortcuts for mobile apps, and create shortcuts for apps

 

 

Preview:

 

Permission required:

1 <uses-permission android: name = "com. android. launcher. permission. INSTALL_SHORTCUT"/>

 

Configuration File: AndroidManifest. xml

1  <activity2             android:name="com.myself.news.activity.GuideActivity"3             android:label="@string/title_activity_guide" >4             <intent-filter>5                 <action android:name="com.myself.news.ACTION_HOME" />6 7                 <category android:name="android.intent.category.DEFAULT" />8             </intent-filter>9         </activity>

 

The oncreate method of the Activity on the application's pop-up page calls installShortcut ();

Code:

1 // create a shortcut 2 // com. android. launcher. permission. INSTALL_SHORTCUT 3 private void installShortcut () {4 // determine whether a shortcut has been created 5 boolean isCreated = SharedPreferencesUtils. getBoolean (this, 6 GlobalConstantsUtils. PREF_IS_SHORTCUT_INTALLED, false); 7 // determine whether 8 if (! IsCreated) {9 // broadcast 10 Intent intent = new Intent (); 11 intent. setAction ("com. android. launcher. action. INSTALL_SHORTCUT "); 12 13 // icon 14 // generate a Bitmap object 15 intent based on the resource file id. putExtra (Intent. EXTRA_SHORTCUT_ICON, BitmapFactory16. decodeResource (getResources (), R. drawable. ic_launcher); 17 // name 18 intent. putExtra (Intent. EXTRA_SHORTCUT_NAME, "mobile security guard"); 19 20 // Action 21 Intent actionIntent = new Intent (); 22 // jump to page 23 actionIntent. setAction (GlobalConstantsUtils. ACTION_HOME); 24 25 intent. putExtra (Intent. EXTRA_SHORTCUT_INTENT, actionIntent); 26 sendBroadcast (intent); 27 28 // mark the created shortcuts. 29 SharedPreferencesUtils will not be created next time. setBoolean (this, 30 GlobalConstantsUtils. PREF_IS_SHORTCUT_INTALLED, true); 31} 32}

 

Constant tool class GlobalConstantsUtils:

 

1 public static final String PREF_IS_SHORTCUT_INTALLED = "is_shortcut_intalled"; // whether a shortcut has been created

1 public static final String ACTION_HOME = "com. myself. news. ACTION_HOME"; // jump to the ACTION on the home page

 

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.