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)