Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Upstream #2

Merged
merged 58 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e019379
代码遗漏更正
sunui Jul 23, 2019
f359a2d
Create the-problem-with-web-components.md (#6181)
sunui Jul 23, 2019
e278786
Google 的 Pagespeed 的工作原理:提升你的分数和搜索引擎排名 (#6153)
Jerry-FD Jul 23, 2019
80da9ca
Create absolute-truths-unlearned-as-junior-developer.md (#6183)
sunui Jul 23, 2019
3b66281
Android 模拟器:Project Marble 中的改进 (#6134)
qiuyuezhong Jul 23, 2019
0073c38
2019 年的 Android 网络 —— Retrofit 与 Kotlin 协程 (#6147)
Feximin Jul 23, 2019
86914be
Create why-ai-is-here-to-stay.md (#6187)
sunui Jul 23, 2019
8d2acac
Create the-rise-of-the-meta-designer.md (#6189)
sunui Jul 23, 2019
fb33403
前端 vs 后端:哪一个适合你? (#6164)
YueYongDev Jul 23, 2019
e76de3a
仅使用 HTML 和 CSS 创建多级嵌套弹出式导航菜单 (#6154)
yzw7489757 Jul 23, 2019
29ad00f
使用 Node.js 读取超大的文件(第一部分) (#6157)
LucaslEliane Jul 23, 2019
7a11153
使用 Cypress 进行 React 应用的端到端测试 (#6137)
donglixiaoche Jul 23, 2019
d70ee94
Delete hermes.md
leviding Jul 23, 2019
d2f2978
利用 84 种认知偏见设计更好的产品 —— 第二部分 (#6168)
JalanJiang Jul 24, 2019
5b92870
从 Reddit 讨论中看到的 GraphQL 现状 (#6140)
TiaossuP Jul 24, 2019
098bc98
Xcode 和 LLDB 高级调试教程:第 3 部分 (#6104)
kirinzer Jul 24, 2019
6d466bf
喷泉码和动态二维码 (#6166)
EmilyQiRabbit Jul 24, 2019
dedde05
Create is-postmessage-slow.md (#6198)
leviding Jul 24, 2019
e47f8a4
Create reverse-engineering-how-you-can-build-a-test-library.md (#6199)
leviding Jul 24, 2019
d3cee00
Create how-data-sharding-works-in-a-distributed-sql-database.md (#6200)
leviding Jul 24, 2019
368b6f2
Create the-open-source-conundrum-how-do-we-keep-the-lights-on.md (#6201)
leviding Jul 24, 2019
e490bee
Create learn-enough-docker-to-be-useful-1.md (#6206)
JackEggie Jul 24, 2019
511f9a0
Go 语言概览 (#6175)
JackEggie Jul 24, 2019
a2815a4
Create typescript-impossible-states-irrepresentable.md (#6208)
sunui Jul 24, 2019
9b17a41
Create writing-a-compiler-in-rust.md (#6216)
JackEggie Jul 25, 2019
e5fa851
CSS 开发必知必会的 16 个调试工具技巧 (#6180)
Usey95 Jul 25, 2019
5c916f0
多网站项目的 CSS 架构 (#6215)
JaxNext Jul 25, 2019
e19974f
Create 5-tips-for-using-showinstallprompt-in-your-instant-experience.…
leviding Jul 25, 2019
94df435
Create when-a-rewrite-isnt-rebuilding-slack-on-the-desktop.md (#6226)
sunui Jul 26, 2019
0439eb9
Create algebraic-effects-for-the-rest-of-us.md (#6225)
sunui Jul 26, 2019
b46ba2e
通过阅读源码提高你的 JavaScript 水平 (#6179)
MarchYuanx Jul 27, 2019
a9620e6
更新部分积分
leviding Jul 27, 2019
96e1b8b
fix
leviding Jul 27, 2019
e645b2c
Update backend.md
leviding Jul 27, 2019
e0c7061
Update front-end.md
leviding Jul 27, 2019
5487eed
更新七月份部分文章翻译校对积分
leviding Jul 27, 2019
16ac249
Update others.md
leviding Jul 27, 2019
6aefcb6
Update android.md
leviding Jul 27, 2019
2b5c198
Update ios.md
leviding Jul 27, 2019
5a85b20
更新七月份部分文章翻译校对积分
leviding Jul 27, 2019
d670241
fix 积分
leviding Jul 27, 2019
3f3f11d
Update design.md
leviding Jul 27, 2019
da03795
Update product.md
leviding Jul 27, 2019
37195fe
更新七月份部分文章翻译校对积分
leviding Jul 27, 2019
8a2bbfa
Create i-built-tic-tac-toe-with-javascript.md
leviding Jul 28, 2019
731988e
Update i-built-tic-tac-toe-with-javascript.md
leviding Jul 28, 2019
eafaad8
作为初级开发人员,我没有学过的 7 个绝对真理 (#6212)
eizyc Jul 28, 2019
4cccf8c
Update front-end.md
leviding Jul 28, 2019
10b9b34
更新七月份部分文章翻译校对积分
leviding Jul 28, 2019
a32b634
Create a-deep-dive-on-python-type-hints.md (#6237)
JackEggie Jul 29, 2019
2abfe86
Create when-every-product-of-design-is-one-of-opinion.md (#6244)
sunui Jul 30, 2019
5037767
Create pika-web-a-future-without-webpack.md (#6248)
sunui Jul 31, 2019
cfc8106
Create what-do-flutter-package-users-need-findings-from-q2-user-surve…
JackEggie Jul 31, 2019
2fba2b5
由浅入深理解主成分分析 (#6231)
Ultrasteve Jul 31, 2019
2723a8c
数据科学家需要掌握的十种统计技术 (#6194)
HearFishle Jul 31, 2019
012e8c9
什么时候需要进行数据的标准化? 为什么? (#6214)
Ultrasteve Jul 31, 2019
277aa24
postMessage 很慢吗? (#6224)
linxiaowu66 Jul 31, 2019
d80b775
更新七月份数据
leviding Jul 31, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[掘金翻译计划](https://juejin.im/tag/%E6%8E%98%E9%87%91%E7%BF%BB%E8%AF%91%E8%AE%A1%E5%88%92) 是一个翻译优质互联网技术文章的社区,文章来源为 [掘金](https://juejin.im) 上的英文分享文章。内容覆盖[区块链](#区块链)、[人工智能](#ai--deep-learning--machine-learning)、[Android](#android)、[iOS](#ios)、[前端](#前端)、[后端](#后端)、[设计](#设计)、[产品](#产品)和[其他](#其他) 等领域,以及各大型优质 [官方文档及手册](#官方文档及手册),读者为热爱新技术的新锐开发者。

掘金翻译计划目前翻译完成 [1684](#近期文章列表) 篇文章,官方文档及手册 [13](#官方文档及手册) 个,共有 [1000](https://github.com/xitu/gold-miner/wiki/%E8%AF%91%E8%80%85%E7%A7%AF%E5%88%86%E8%A1%A8) 余名译者贡献翻译和校对。
掘金翻译计划目前翻译完成 [1726](#近期文章列表) 篇文章,官方文档及手册 [13](#官方文档及手册) 个,共有 [1000](https://github.com/xitu/gold-miner/wiki/%E8%AF%91%E8%80%85%E7%A7%AF%E5%88%86%E8%A1%A8) 余名译者贡献翻译和校对。

> ## [🥇掘金翻译计划 — 区块链分舵](https://github.com/xitu/blockchain-miner)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,21 @@ var response = await rp(‘https://api.example.com/endpoint1');

2. **错误处理:** Async/await 使得我们可以使用相同的代码结构处理同步或者异步的错误 —— 著名的 try/catch 语句。让我们看看用 Promises 是怎么实现的:

```js
function loadData() {
try { // Catches synchronous errors.
getJSON().then(function(response) {
var parsed = JSON.parse(response);
console.log(parsed);
}).catch(function(e) { // Catches asynchronous errors
console.log(e);
});
} catch(e) {
console.log(e);
}
}
```

对比:

```js
Expand Down
212 changes: 106 additions & 106 deletions TODO1/16-devtools-tips-and-tricks-every-css-developer-need-to-know.md

Large diffs are not rendered by default.

136 changes: 136 additions & 0 deletions TODO1/5-tips-for-using-showinstallprompt-in-your-instant-experience.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
> * 原文地址:[5 tips for using showInstallPrompt in your instant experience](https://medium.com/androiddevelopers/5-tips-for-using-showinstallprompt-in-your-instant-experience-99d4681e0ae)
> * 原文作者:[Miguel Montemayor](https://medium.com/@migmontemayor)
> * 译文出自:[掘金翻译计划](https://github.com/xitu/gold-miner)
> * 本文永久链接:[https://github.com/xitu/gold-miner/blob/master/TODO1/5-tips-for-using-showinstallprompt-in-your-instant-experience.md](https://github.com/xitu/gold-miner/blob/master/TODO1/5-tips-for-using-showinstallprompt-in-your-instant-experience.md)
> * 译者:
> * 校对者:

# 5 tips for using showInstallPrompt in your instant experience

![](https://cdn-images-1.medium.com/max/3200/0*5eAOuRUKrRBXEJdI)

[Google Play Instant](https://developer.android.com/topic/google-play-instant) allows your users to try your app or game before installing. Whether launching from the Play Store or a URL, instant experiences take your users directly into a native experience of your app.

One of the goals of your instant experience may be to drive installs from your app’s instant experience. You can achieve this more easily by making sure you are correctly using the latest APIs and best practices.

When users decide to install your app or game, the [showInstallPrompt API](https://developers.google.com/android/reference/com/google/android/gms/instantapps/InstantApps.html#showInstallPrompt(android.app.Activity,%20android.content.Intent,%20int,%20java.lang.String)) allows you to prompt for installation from within your instant experience. After calling the API, an in-app install prompt overlay appears in your app. Once the user agrees to install, the app installation process begins. When completed, the installed app launches automatically.

![**This animation shows the installation flow when using showInstallPrompt**](https://cdn-images-1.medium.com/max/2000/0*HaJS3sMgtdYB_TxA)

When implementing showInstallPrompt in your instant experience, the best practices detailed below that will make transitioning your users from instant to installed app as smooth as possible.

## 1. Make sure you’re using the latest showInstallPrompt API

Rolled out in June 2018, the updated [showInstallPrompt API](https://developers.google.com/android/reference/com/google/android/gms/instantapps/InstantApps.html#showInstallPrompt(android.app.Activity,%20android.content.Intent,%20int,%20java.lang.String)) gains a few key benefits over the legacy API. The new API displays a smaller install prompt and improves the transition to your installed app with the addition of the postInstallIntent parameter, which specifies the activity to launch after installation.

> Identifying the showInstallPrompt version in your instant experience

Previously, the legacy API would launch a larger in-app install prompt. Due to the legacy showInstallPrompt deprecation, now calling it launches your Play Store listing. In order to restore in-app install prompts, you’ll need to migrate to the new API.

If you’re not sure whether your instant experience calls the legacy API, you can quickly figure out by running your instant app and selecting the install button. If you’re taken to the Play Store listing, you’re using the legacy API. If you see an in-app overlay, you’re using the latest API.

Alternatively, you can check your code to see if your method call includes the postInstallIntent parameter. If it does not include the postInstallIntent, you’re using the legacy API. Here’s the method signature of the new showInstallPrompt API:

```
public static boolean showInstallPrompt (Activity activity, Intent postInstallIntent, int requestCode, String referrer)
```

The `postInstallIntent` is the intent that will launch after the app has been installed. It must resolve to an activity in the installed app package, or it will not be used.

> Migrating to the new showInstallPrompt

To migrate to the new showInstallPrompt API, follow these steps:

1. Make sure you are using the latest instant app client library in your project. Update the following dependency in your build.gradle file:

```
implementation 'com.google.android.gms:play-services-instantapps:16.0.1'
```

2. Update your code to use the new [showInstallPrompt API](https://developers.google.com/android/reference/com/google/android/gms/instantapps/InstantApps.html#showInstallPrompt(android.app.Activity,%20android.content.Intent,%20int,%20java.lang.String)) with the postInstallIntent parameter.

3. Upload your instant app to the [internal test track](https://support.google.com/googleplay/android-developer/answer/3131213?hl=en) to verify that the install button now launches an in-app install prompt overlay.

You can also look through this [sample app](https://github.com/googlesamples/android-instant-apps/tree/master/install-api) using the new showInstallPrompt API to see how this works.

## 2. Pre-register from within your instant game

The showInstallPrompt API is not just for installation! If your instant game supports [pre-registration](https://support.google.com/googleplay/android-developer/answer/9084187), you can prompt for pre-registration signup using the same API.

When your app calls showInstallPrompt, the behavior for pre-registration is similar to what appears during installation. An in-app overlay appears to pre-register the user. Then the user will be able to continue where they left off in the instant game. Users who pre-register will be notified when the game is released.

To launch the pre-registration flow, you call showInstallPrompt just as if you were going to prompt for install.

```
// Prompt for pre-registration
InstantApps.showInstallPrompt(activity, postInstallIntent, requestId, referrerId)
```

Note the `postInstallIntent` parameter is ignored after pre-registration is completed.

## 3. Transition user state to the installed app

Transfer the user’s state from the instant experience into the installed app. Users should be able to pick up where they left off. Any achievements or progress made in the instant experience should carry over to the installed app or game.

![](https://cdn-images-1.medium.com/max/2000/0*r7DBqy2P92QFwOPf)

The recommended way to persist user state is using the [Cookie API](https://developers.google.com/android/reference/com/google/android/gms/instantapps/PackageManagerCompat#getInstantAppCookie()) for migrating data after installation. The Cookie API allows you to store a small token of information on the device that can be accessed by your installable app. The API ensures that only apps with the same package ID as your instant app can access the cookie.

In your instant app, you should always store your cookie data by using [PackageManagerCompat](https://developers.google.com/android/reference/com/google/android/gms/instantapps/PackageManagerCompat.html#setInstantAppCookie(byte[])).

```Kotlin
// Cookie data is a simple byte array.
val cookieData: ByteArray = byteArrayOf()

// Use PackageManagerCompat to access Cookie API
val packageManager = InstantApps.getPackageManagerCompat(applicationContext)

// Ensure that the cookie data will fit within the store before setting
// the value.
if (cookieData.length <= packageManager.getInstantAppCookieMaxSize()) {
packageManager.setInstantAppCookie(cookieData)
}
```

After the user installs the app, you can access the data.

```Kotlin
// Use PackageManagerCompat to access Cookie API.
val packageManager = InstantApps.getPackageManagerCompat(this)
val cookieData = packageManager.getInstantAppCookie()

// Clear the cookie data once it has been read to clear it.
packageManager.setInstantAppCookie(null)
```

## 4. Don’t interfere with task completion

Users shouldn’t be interrupted when working through the tasks they sought to complete when opening the instant experience. Avoid asking users to install your app when they’re partially completed with a task.

You can call showInstallPrompt after the user has completed their task or wants to use an additional feature not available in your instant app.

![](https://cdn-images-1.medium.com/max/2000/1*uovyCegQYpdiurkTpTL5lQ.png)

For example, if you lead users to an instant experience through a product ad online, your instant app should allow your users to complete the checkout flow. After the purchase is completed, you can prompt for install. Avoid requiring the user to install or sign up before they can complete their purchase.

## 5. Provide explicit installation prompts

This last tip may seem obvious, but make sure your instant experience has explicit install prompts. Without them, users may be confused on how to install your app or may have to go to the Play Store to install.

The install buttons should call showInstallPrompt to launch the install prompt.

![](https://cdn-images-1.medium.com/max/2000/1*nKfEwwU4dVp08ZUndHvuIA.png)

Use the [Material Design “get app” icon](https://material.io/icons/#ic_get_app) and the label “Install” for the installation button or “Pre-Register” for the pre-registration button.

Don’t use any other labels like “Get the app”, “Install the full app,” or “Upgrade”. Don’t use a banner or other ad-like technique for presenting an installation prompt to users.

***

If you have additional questions about implementing the showInstallPrompt API in your instant app or game, post your question on [StackOverflow](https://stackoverflow.com/questions/tagged/android-instant-apps). Learn more about [Google Play Instant](https://developer.android.com/topic/google-play-instant) and check out our other [UX best practices](https://developer.android.com/topic/google-play-instant/best-practices/apps).

> 如果发现译文存在错误或其他需要改进的地方,欢迎到 [掘金翻译计划](https://github.com/xitu/gold-miner) 对译文进行修改并 PR,也可获得相应奖励积分。文章开头的 **本文永久链接** 即为本文在 GitHub 上的 MarkDown 链接。

---

> [掘金翻译计划](https://github.com/xitu/gold-miner) 是一个翻译优质互联网技术文章的社区,文章来源为 [掘金](https://juejin.im) 上的英文分享文章。内容覆盖 [Android](https://github.com/xitu/gold-miner#android)、[iOS](https://github.com/xitu/gold-miner#ios)、[前端](https://github.com/xitu/gold-miner#前端)、[后端](https://github.com/xitu/gold-miner#后端)、[区块链](https://github.com/xitu/gold-miner#区块链)、[产品](https://github.com/xitu/gold-miner#产品)、[设计](https://github.com/xitu/gold-miner#设计)、[人工智能](https://github.com/xitu/gold-miner#人工智能)等领域,想要查看更多优质译文请持续关注 [掘金翻译计划](https://github.com/xitu/gold-miner)、[官方微博](http://weibo.com/juejinfanyi)、[知乎专栏](https://zhuanlan.zhihu.com/juejinfanyi)。
Loading