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

【Android】实现类似于QQ将好友的头像用作快捷方式。

时间:2015-05-18 16:50:03      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

原因:

写这个的原因就是网上大都是告诉你如何用drawable里的资源做快捷方式,那么本地的图片能不能做快捷方式呢?肯定是可以的,所以我找了下安卓的源码,发现有这样的介绍
    /**
     * Activity Action: Creates a shortcut.
     * <p>Input: Nothing.</p>
     * <p>Output: An Intent representing the shortcut. The intent must contain three
     * extras: SHORTCUT_INTENT (value: Intent), SHORTCUT_NAME (value: String),
     * and SHORTCUT_ICON (value: Bitmap) or SHORTCUT_ICON_RESOURCE
     * (value: ShortcutIconResource).</p>
     *
     * @see #EXTRA_SHORTCUT_INTENT
     * @see #EXTRA_SHORTCUT_NAME
     * @see #EXTRA_SHORTCUT_ICON
     * @see #EXTRA_SHORTCUT_ICON_RESOURCE
     * @see android.content.Intent.ShortcutIconResource
     */

不难看出有两种方式创建快捷方式图标,不过大都用的第一种。所以我们就试试第二种吧。

解决方案:

既然都看了源码的介绍了,自然就知道怎么做了。
	public void CreateShotCast(Context context, Class<?> clazz) {
		Intent shortcut = new Intent(Intent.ACTION_CREATE_SHORTCUT);
		
		Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
		shortcutIntent.setClass(context, clazz);
		
		shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
		shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "测试");
		// Intent.EXTRA_SHORTCUT_ICON 是bitmap对象
		shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeFile("路径"));
		context.sendBroadcast(shortcut);
	}


【Android】实现类似于QQ将好友的头像用作快捷方式。

标签:

原文地址:http://blog.csdn.net/windowsxp2014/article/details/45822757

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