Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PWA interoperability with Android apps/services?

We know that some of our code must be in native code, but it can be encapsulated as an Android service. We would like to create the UI-oriented part as a progressive web app (PWA).

Is there a way for the PWA to interact with native apps on the device (e.g., call them with parameters and handle replies/broadcasts of the other app)?

Can the PWA call intents, be called as an intent, etc? What are the possibilities?

like image 655
Danikenan Avatar asked Nov 29 '16 06:11

Danikenan


People also ask

Do progressive Web apps work on Android?

On both Android and iOS, users can't install PWAs from many in-app browsers, such as Facebook Mobile Browser, Instagram, Google Search App, or Gmail. In the following video the user installs a PWA from the browser on a mobile device using the browser dialog, and also using the Add to Home screen menu.

How do I convert PWA to Android app?

Try It Out - BubblewrapCreate a directory to hold your generated Android project. Initialize that directory with Bubblewrap and your PWA's Web App Manifest. Generate new Signing Key, or reuse your existing ones if you have them. Build your Android App Bundle from the generated Android project.

Will PWA replace mobile apps?

PWAs can do most things native apps can and many native apps could easily be replaced by a PWA. But ironically iOS, the platform of the company whose co-founder first presented the idea of a PWA, is lacking behind.

Can PWA be hosted on App Store?

To generate an iOS app, you just need a PWA. Or more specifically, a web app with a manifest. To build the project, you'll need a Mac with Xcode installed. To publish your PWA to the iOS App Store, you'll need an Apple Developer account.


1 Answers

Sending Share Intent (via Web Share API)

At the Chrome Dev Summit 2016, the team announced the Web Share API, which allows PWAs to invoke the native sharing capabilities of the device (e.g., see Android demo video) in response to a user gesture (e.g., by clicking a link; cannot be automatic). The API is very new and behind an origin trial.

The following example click-handler invokes the Share Intent, which brings up the native app picker to share data with a user-chosen app. Passing a URL (optional) allows that app to provide a link to the user e.g. for a detail view.

function onClick() {
    navigator.share({
        title: document.title,
        text: "Hello World",
        url: window.location.href
    })
    .then(() => console.log('Successful share'))
    .catch(error => console.log('Error sharing:', error));
}

Sending Android Intents from Chrome

It's possible to send an Android intent from a PWA with intent URLs. This method also requires a user gesture to initiate (e.g., by clicking a link; cannot be automatic).

The intent syntax is:

intent:
   HOST/URI-path // Optional host 
   #Intent; 
      package=[string]; 
      action=[string]; 
      category=[string]; 
      component=[string]; 
      scheme=[string]; 
   end; 

For example, clicking this anchor tag launches the ZX Barcode Scanner app:

<a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end"> Take a QR code </a>

Receiving Android Intents

I found nothing on PWAs receiving intents or broadcast messages from native apps. I don't think it's possible.

like image 200
tony19 Avatar answered Sep 20 '22 05:09

tony19