1 year ago

#327658

test-img

David Márquez Fàbrega

How to install a PWA with Android WebView/TWA

Scenario

I have an existing native android app in which I want to add some new features. These features have already been implemented as a PWA because some users needed to use them directly from the web.

I want to be able to open the PWA with an Android WebView (as if it was part of my native application) and install it 'locally'. With 'locally' I mean that the PWA should not be visible as an app in the phone, it would just be part of my existing native app. In a way, what I'm trying to achieve is a king of "plugin" system, where I could have extra features that the user can install to the native app.

Where am I stuck?

Opening the PWA with a WebView is fairly straight forward. The part that I am unable to do is installing the PWA. Maybe TWA could solve this issue, but I am not sure it is meant for that.

Moreover, ideally I would like to keep everything in a Fragment since I would like to have the toolbar and others created by the native app (that is why I've leaned more towards using WebView instead of TWA).

EDIT---------------

After messing around I was able to understand that it actually gets installed with WebView. Since I haven't been able to find any information about how it works online I've been researching it on my own.

First of all ServiceWorkerController is only available from Android 7 (24). I haven't been able to test if with Android 6 this can work or not due to the fact that I don't have any phone with that version and I can't update the WebView apk of my emulators for some reason.

Then, I found out that the webpage crashed in my newer emulators because the WebView apk installed was too low and didn't support some newer features. So another thing to take into consideration the WebView version installed. This apk gets installed separately from the Android version (it's as if it was an app on your phone). The solution to this is to just use a real device, because the apk is usually always up to date.

As you can see in the following picture the PWA gets installed inside the app folder and it also keeps all the info (databases, localstorage, sessionstorage, etc.) in there. enter image description here

It is unclear how this data is handled (I created this question) but it appears to be at least in the following cases:

  1. WebStorage.Instance.DeleteAllData()
  2. App uninstalled
  3. App Data Cleared

Clearing the Cache of the app doesn't delete the persistent data.

So now I would say that the question would be:

  1. From which Android Version does the Service Worker install? Just from the Android version that has support for the webview apk version that supports Service Workers?
  2. Does it depend at all on ServiceWorkerController? Or is it just a utility class to have more control over what happens?

android

android-webview

progressive-web-apps

trusted-web-activity

0 Answers

Your Answer

Accepted video resources