PWA interoperability with Android apps/services?

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

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?

profilepic.png
manpreet 2 years ago

 

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:

 Take a QR code 

Receiving Android Intents

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


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community