You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求JavaScript Service Worker接收Android Intent的新API官方链接

关于接收Android Intent的Service Worker相关能力

你提到的接收Android Intent并触发指定链接的功能,核心是Web App Manifest的Intent过滤器配置结合Service Worker的导航拦截能力,这是Chrome for Android对Web App提供的原生关联支持,并非一个独立的新API,而是Web App现有能力的组合:

  • 首先在Web App的manifest.json中配置intent_filters,声明你的Web App可以响应的Android Intent规则,比如匹配https://my.app/scancode/details这类链接的VIEW动作Intent:
{
  "name": "My App",
  "start_url": "/",
  "display": "standalone",
  "intent_filters": [
    {
      "action": "android.intent.action.VIEW",
      "category": ["android.intent.category.DEFAULT", "android.intent.category.BROWSABLE"],
      "data": {
        "scheme": "https",
        "host": "my.app",
        "pathPrefix": "/scancode/details"
      }
    }
  ]
}
  • 当Android系统发送匹配的Intent时,Web App会被唤醒,此时Service Worker可以通过fetch事件拦截对应的导航请求,处理业务逻辑:
self.addEventListener('fetch', (event) => {
  const requestUrl = new URL(event.request.url);
  if (requestUrl.host === 'my.app' && requestUrl.pathname.startsWith('/scancode/details')) {
    // 这里可以添加自定义处理逻辑,比如从缓存加载或发起网络请求
    event.respondWith(
      caches.match(event.request)
        .then(cachedResponse => cachedResponse || fetch(event.request))
    );
  }
});

这个功能属于Web App的App Linking(应用链接)范畴,核心是让Web App可以像原生Android应用一样接收系统Intent,相关规范和实现细节由Chrome开发者文档维护。

内容的提问来源于stack exchange,提问作者Anton Kotikov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 03:10:59