android7.0上新特性--(快捷方式) App shortcuts overview

先上官网了解一波 https://developer.android.google.cn/guide/topics/ui/shortcuts?hl=en

android7.0上新特性--(快捷方式) App shortcuts overview

Shortcuts是什么?

Shortcuts是指在桌面长按App图标而出现的快捷方式,可以为你的App的关键功能添加更快速的入口而不用先打开App。

Shortcuts分类及使用场景:

  • 静态快捷方式
  • 动态快捷方式
  • 固定快捷方式

android7.0上新特性--(快捷方式) App shortcuts overview
今天我们来看看静态快捷方式该如何使用,以及我们需要注意的问题:

1.静态快捷方式的创建步骤:

android7.0上新特性--(快捷方式) App shortcuts overview

android7.0上新特性--(快捷方式) App shortcuts overview

2.我们知道创建的流程了,接下来我们开始以一个示例来说明,如果我们要app实现以下功能,该如何操作呢?

android7.0上新特性--(快捷方式) App shortcuts overview

2.1 manifest声明:

android7.0上新特性--(快捷方式) App shortcuts overview

2.2 创建 res/xml/shortcuts目录:

android7.0上新特性--(快捷方式) App shortcuts overview

2.3 res/value/strings目录:

android7.0上新特性--(快捷方式) App shortcuts overview

2.4 代码编写:

android7.0上新特性--(快捷方式) App shortcuts overview

2.5 点击不同的快捷入口,页面展示:

    android7.0上新特性--(快捷方式) App shortcuts overviewandroid7.0上新特性--(快捷方式) App shortcuts overviewandroid7.0上新特性--(快捷方式) App shortcuts overview

3.shortcuts属性:

android7.0上新特性--(快捷方式) App shortcuts overview

4.shortcuts相关注意点:

android7.0上新特性--(快捷方式) App shortcuts overview

  • 手机系统必须是7.0以上的, Shortcut 总和不能超过 5 个,通常以4个为宜;
  • 无法动态改变静态shortcut的展示顺序,它们是按照shortcuts.xml文件中定义的顺序来显示的;
  • 静态Shortcuts只能通过升级应用来进行update且Intent无法设置Flag,默认为FLAG_ACTIVITY_NEW_TASK 和 FLAG_ACTIVITY_CLEAR_TASK,即应用运行中会清除所有已存在的Activity;
  • 快捷方式中的元数据应该隐藏敏感的用户信息;