Android-Add a URL icon to the mobile desktop (solution 2)

Source: Internet
Author: User

Android-Add a URL icon to the mobile desktop (solution 2)

The previous article mainly opened the app to enable the website. Although it is relatively simple to implement, the effect is still flawed.

This article uses the Broadcast mechanism to implement the desktop icon link URL function, which not only works well, but also has the biggest advantage that you no longer need to use the app to open the website.

The implementation steps are as follows:

1. add permissions to the AndroidManifest. xml configuration file:

    
     
 

2. Set and add the broadcast listening Intent in the OnCreate method of MainActivity:

Final Intent shortCutIntent = new Intent ("com. android. launcher. action. INSTALL_SHORTCUT "); final Parcelable icon = (BitmapDrawable) context. getResources (). getDrawable (R. drawable. ic_launcher )). getBitmap (); // retrieve the icon Uri uri of the shortcut key = Uri. parse ("http://blog.csdn.net/wanggsx918"); Intent pendingIntent = new Intent (Intent. ACTION_VIEW, uri); // The shortCutIntent icon on the desktop. putExtra (Intent. EXTRA_SHORTCUT_ICON, icon); // desktop shortcut title shortCutIntent. putExtra (Intent. EXTRA_SHORTCUT_NAME, context. getString (R. string. app_name); // desktop shortcut Action: The action shortCutIntent when the icon is clicked. putExtra (Intent. EXTRA_SHORTCUT_INTENT, pendingIntent); context. sendBroadcast (shortCutIntent );

Yes, this implementation method is both authentic and perfect. This is the taste!

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.