The previous article is mainly to open the app to achieve 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, and the biggest advantage is no longer the use of the app to open the site.
The implementation process is as follows:
1, in the Androidmanifest.xml configuration file to add permissions:
<uses-permission android:name= "Com.android.launcher.permission.READ_SETTINGS"/> <uses-permission Android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>
2, in the mainactivity in the OnCreate method to set up and join the broadcast monitoring intent:
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)