码迷,mamicode.com
首页 > 移动开发 > 详细

android--手机桌面增加网址链接图标(解决方案二)

时间:2014-10-28 17:52:04      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:android   网址   链接   图标   广播   

前一篇文章主要是通过打开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" />

2、在MainActivity中的OnCreate方法中设置和添加广播监听Intent:

		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);

没错,此种实现方式既正宗,又完美。要的就是这个口味!

android--手机桌面增加网址链接图标(解决方案二)

标签:android   网址   链接   图标   广播   

原文地址:http://blog.csdn.net/wanggsx918/article/details/40541993

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!