标签:blog 广播 track draw wan xml配置 gets app 动作
前一篇文章主要是通过打开app来实现打开网址的功能。尽管实现起来比較简单,但从效果上来说还是有缺陷。
本文将借助于Broadcast广播机制来实现桌面图标链接网址的功能。不仅效果好,并且最大的长处就是不用再借助于app应用来打开站点了。
实现过程例如以下:
1、在AndroidManifest.xml配置文件里加入权限:
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> final Intent shortCutIntent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
final Parcelable icon = ((BitmapDrawable)context.getResources().getDrawable(R.drawable.ic_launcher)).getBitmap(); // 获取快捷键的图标
Uri uri = Uri.parse("http://blog.csdn.net/wanggsx918");
Intent pendingIntent = new Intent(Intent.ACTION_VIEW, uri);
//桌面快捷方式图标
shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
//桌面快捷方式标题
shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
context.getString(R.string.app_name));
//桌面快捷方式动作:点击图标时的动作
shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, pendingIntent);
context.sendBroadcast(shortCutIntent);标签:blog 广播 track draw wan xml配置 gets app 动作
原文地址:http://www.cnblogs.com/ljbguanli/p/6932621.html