欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Android实现类似于QQ将好友的头像用作快捷方式,android类似于,原因: 写这个的原因就是

来源: javaer 分享于  点击 4229 次 点评:156

Android实现类似于QQ将好友的头像用作快捷方式,android类似于,原因: 写这个的原因就是


原因: 写这个的原因就是网上大都是告诉你如何用drawable里的资源做快捷方式,那么本地的图片能不能做快捷方式呢?肯定是可以的,所以我找了下安卓的源码,发现有这样的介绍```java* * 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 /

不难看出有两种方式创建快捷方式图标,不过大都用的第一种。所以我们就试试第二种吧。解决方案:既然都看了源码的介绍了,自然就知道怎么做了。```java    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);      }  

来自:http://blog.csdn.net/windowsxp2014/article/details/45822757

相关栏目:

用户点评