How exactly are we supposed to implement the Native App Install Prompt for Chrome on Android?
Asked Answered
C

1

11

I'm looking at the Google documentation at https://developers.google.com/web/fundamentals/app-install-banners/native, trying to figure out how to show an install banner on Chrome for Android to install our native app.

First of all, in a couple of places, this page refers to adding your app to the home screen, which is not what this page is supposed to be about, right? This is supposed to be about installing native apps, not PWAs.

But my real question is: what is the flow supposed to look like in the real world? If all the proper conditions are met, we're supposed to display a button or some other thing the user can interact with, and then Chrome shows an install banner? So, we show a button or a banner that says "Install our app", and then if the user clicks it, Chrome displays another banner that says "Install"? This seems like a very redundant experience, requiring more button clicks to install than just showing the Chrome install banner automatically (which is how I gather it used to work).

I've done a bunch of searches, but can't find any examples where people show how they're using this current flow. Is anyone actually using this?

Should I just use something like https://github.com/ain/smartbanner.js instead?

Coff answered 24/4, 2019 at 20:53 Comment(2)
FYI Chrome uses the infobar both for PWA and native app: i.sstatic.net/CF4lU.pngWhitesell
I ended up just using smartbanner.js for Android.Coff
V
17

The docs are confusing, misleading and often refer to PWA's. Once you have the manifest and meet the requirements, there will be a native banner that appears with an install link or add to home screen link. Here are my updated requirements for Android smart app banner and how to test it. I included one missing criteria from the docs: multiple different icon sizes are required.


Android Native App Install Prompt Requirements

  • The web app nor the native app are already installed.
  • Meets a user engagement heuristic (currently, the user has interacted with the domain for at least 30 seconds)
  • Includes a Web App Manifest that includes:
    • short_name
    • name (used in the banner prompt)
    • icons including a 36x36, 48x48, 72x72, 96x96, 144x144, 192x192, 512x512 version
    • prefer_related_applications is true
    • related_applications object with information about the app
  • start_url can be set to . for the current location
  • Manifest is served over HTTPS - manifest.json
    • include this on your page <link rel="manifest" href="manifest.json" />

Testing

  • Login to chrome on your Android device or emulator
  • Login to the Google Play store (must have play store on device)
  • Enable this flag in chrome chrome://flags/#bypass-app-banner-engagement-checks
  • The app should not already be installed on the device

Debugging

Inspect the sources tab in your browser to see if the manifest is served correctly and remember to check the console for any errors (warnings are fine)

Example

manifest.json

{
  "name": "App Name",
  "short_name": "App Name Install Banner Sample",
  "icons": [
    {
      "src": "icon-0-75x.png",
      "sizes": "36x36",
      "type": "image/png"
    },
    {
      "src": "icon-1x.png",
      "sizes": "48x48",
      "type": "image/png"
    },
    {
      "src": "icon-1-5x.png",
      "sizes": "72x72",
      "type": "image/png"
    },
    {
      "src": "icon-2x.png",
      "sizes": "96x96",
      "type": "image/png"
    },
    {
      "src": "icon-3x.png",
      "sizes": "144x144",
      "type": "image/png"
    },
    {
      "src": "icon-4x.png",
      "sizes": "192x192",
      "type": "image/png"
    }
  ],
  "prefer_related_applications": true,
  "related_applications": [
    {
      "platform": "play",
      "id": "com.google.samples.apps.iosched",
      "url": "https://play.google.com/store/apps/details?id=com.google.samples.apps.iosched"
    }
  ],
  "start_url": ".",
  "display": "standalone"
}
Vida answered 18/3, 2021 at 21:59 Comment(3)
Thank you for this. I have a question: According to the docs, a native install prompt should let the user install a native app "quickly and seamlessly". I understand this means that the user does not have to make a roundtrip to the store. Is this correct? I have implemented exactly as you described, and i get the beforeinstallprompt event. When I prompt() on the event, an 'add to homescreen' message is shown. When clicking on 'install' the store is opened. Do you have an example app where this is working?Duodiode
@DavidStrahm From what I have found, the user will still need to visit the store. I imagine there are security and privacy reasons for this (so you don't download something unsafe on accident). Here is a working example with the above implementation for Android. On web, if you open your inspector, you can navigate to the Sources tab and go to the file tree path top/coach.ncsasports.org/coach/resources. There you will find a manifest.json file for reference.Vida
Yes, this is exactly the same behavior that I have. It seems it is really necessary to visit the store, The documentation is indeed misleading.Duodiode

© 2022 - 2024 — McMap. All rights reserved.