blob: 104794a6b2dbe24bc8cf1679496f559842254073 [file] [log] [blame]
<html devsite><head>
<title>微件/快捷方式</title>
<meta name="project_path" value="/_project.yaml"/>
<meta name="book_path" value="/_book.yaml"/>
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>
借助 Android 8.0 中新增的用于添加快捷方式和微件的流程 API,应用开发者可以从应用内添加快捷方式和微件,而不需要依靠微件面板。出于安全考虑,Android 8.0 还弃用了用于添加快捷方式的旧方法(发送广播)。
</p>
<p>
启动器需要支持这种新的实现,以便应用开发者可以依靠系统来添加其快捷方式或微件。
</p>
<h2 id="examples-and-source">示例和来源</h2>
<p>
有关于各种系统类的文档可供参考。参考资料包括:
</p>
<ul>
<li><b><a href="https://developer.android.com/reference/android/content/pm/ShortcutManager.html">ShortcutManager.java</a></b><br />
在标题中发布已固定的快捷方式部分。
</li><li><b>Intent.java</b><br />关于 ACTION_CREATE_SHORTCUT 的 Javadoc。</li>
<li><b>AppWidgetManager.java</b><br />关于 requestPinAppWidget 的 Javadoc。</li>
</ul>
<h2 id="implementation">实现</h2>
<p>
设备实现者需要通过 intent 过滤器操作在其启动器中添加一个 Aactivity:
</p>
<ul>
<li><code>android.content.pm.action.CONFIRM_PIN_SHORTCUT</code></li>
<li><code>android.content.pm.action.CONFIRM_PIN_APPWIDGET</code></li>
</ul>
<p>
如需更多详细信息,请参阅 <a href="https://developer.android.com/reference/android/content/pm/LauncherApps.html">API 文档</a>
</p>
<p>
该 Activity 应向用户显示关于添加<a href="https://developer.android.com/reference/android/content/pm/LauncherApps.html">请求的微件/快捷方式</a>的确认提示,并在用户接受后,在主屏幕上添加相应的微件/快捷方式。
</p>
<p>
对于微件,<code>accept()</code> 调用应包含新添加微件的 ID。
</p>
<h3 id="implementing-a-system-ui">实现系统界面</h3>
<p>
合作伙伴需要参考 Launcher3 实现 (<code>packages/apps/Launcher3</code>) 来更新其启动器应用。
</p>
<p>
在 Android 开源项目 (AOSP) 中查找相关的 Launcher3 更改:
</p>
<ul>
<li>Change-Id:<a href="https://android.googlesource.com/platform/packages/apps/Launcher3/+/8b2002e28072c52d78f6d052c6ff6da50a2d0324">8b2002e28072c52d78f6d052c6ff6da50a2d0324</a>
</li><li>Change-Id:<a href="https://android.googlesource.com/platform/packages/apps/Launcher3/+/278359539c02ca160caf1df54ce96053a2a2ef59">278359539c02ca160caf1df54ce96053a2a2ef59</a>
</li></ul>
<h2 id="validation">验证</h2>
<p>
要验证该功能,请尝试从 Chrome 或通讯录应用添加快捷方式,并验证系统是否会显示正确的确认提示。在接受提示后,图标应已添加到主屏幕上,并且 Chrome 应显示一个提示添加成功的消息框。
</p>
</body></html>