PWA 与 Android 应用程序/服务的互操作性? [英] PWA interoperability with Android apps/services?

查看:41
本文介绍了PWA 与 Android 应用程序/服务的互操作性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道我们的一些代码必须是原生代码,但是可以封装成Android服务.我们希望将面向 UI 的部分创建为渐进式网络应用 (PWA).

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).

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)?

PWA 调用 Intent 是否可以作为 Intent 调用等?有哪些可能性?

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

推荐答案

Sending Share Intent (via Web Share API)

Chrome Dev Summit 2016 上,该团队宣布了 Web Share API,它允许 PWA 调用设备的本机共享功能(例如,请参阅 Android 演示视频)以响应用户手势(例如,通过单击链接;不能自动).该 API 非常新,并且是在原始试验之后.

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.

以下示例点击处理程序调用 Share Intent,它会调出本机应用选择器以与用户选择的应用共享数据.传递 URL(可选)允许该应用程序向用户提供链接,例如查看详细视图.

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));
}

从 Chrome 发送 Android Intent

可以使用意图网址从 PWA 发送 Android 意图.此方法还需要用户手势来启动(例如,通过单击链接;不能是自动的).

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).

意图语法是:

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

例如,单击此锚点标签会启动 ZX Barcode Scanner 应用程序:

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>

接收 Android Intents

我没有发现 PWA 从本机应用程序接收意图或广播消息.我认为这不可能.

Receiving Android Intents

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

这篇关于PWA 与 Android 应用程序/服务的互操作性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆