Android实现类似于QQ将好友的头像用作快捷方式
发布时间:2020-05-28 21:53:57 所属栏目:Java 来源:互联网
导读:Android实现类似于QQ将好友的头像用作快捷方式
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 原因:写这个的原因就是网上大都是告诉你如何用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);
}
来自:http://blog.csdn.net/windowsxp2014/article/details/45822757 以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
