android--Mobile Desktop Add URL link icon (Solution II)

Source: Internet
Author: User

The previous article is mainly by opening the app to realize the function of opening the URL, although the implementation is relatively simple, but the effect is still flawed.

This article will use the broadcast broadcasting mechanism to realize the function of the desktop Icon link URL, not only the effect is good, but also the biggest advantage is not to use the app to open the site.

The implementation steps are as follows:

1. Add permissions in the Androidmanifest.xml configuration file:

    <uses-permission android:name= "Com.android.launcher.permission.READ_SETTINGS"/>    <uses-permission Android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>

2. Set and add the broadcast listener intent in the OnCreate method in Mainactivity:

Final Intent shortcutintent = new Intent ("Com.android.launcher.action.INSTALL_SHORTCUT"); final parcelable icon = (( bitmapdrawable) context.getresources (). getdrawable (R.drawable.ic_launcher)). Getbitmap (); Gets the icon Uri URI of the shortcut key = Uri.parse ("http://blog.csdn.net/wanggsx918");    Intent pendingintent = new Intent (Intent.action_view, URI);//Desktop shortcut icon Shortcutintent.putextra (intent.extra_shortcut_ icon, icon);//Desktop shortcut title Shortcutintent.putextra (intent.extra_shortcut_name,context.getstring (r.string.app_name)) ///Desktop shortcut action: Click on the icon when the action Shortcutintent.putextra (Intent.extra_shortcut_intent, pendingintent); Context.sendbroadcast ( Shortcutintent);

True, this approach is both authentic and perfect. That's the taste!

android--Mobile Desktop Add URL link icon (Solution II)

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.