跳转至正文

意图启动器 Capacitor 插件

启动 Android Intent、打开系统设置,并通过 Intent 系统与其他应用交互

安装

bun add @capgo/capacitor-intent-launcher bunx cap sync
npm、pnpm 或 yarn
  • npm install @capgo/capacitor-intent-launcher
  • pnpm add @capgo/capacitor-intent-launcher
  • yarn add @capgo/capacitor-intent-launcher

指南

如何在 Capacitor 中使用 Intent Launcher

在设备上测试

下载 Capgo App,然后扫描二维码 code。

Intent Launcher 插件预览二维码 code

使用 @capgo/capacitor-intent-launcher

Capacitor Intent Launcher 插件,用于在 Android 和 iOS 上启动 Android intent 并打开系统设置。

安装

bun add @capgo/capacitor-intent-launcher
bunx cap sync

bunx cap sync 将插件的原生 code 复制到你的原生项目中。每次升级插件后都要重新运行。

导入

import { IntentLauncher } from '@capgo/capacitor-intent-launcher';

API 概览

方法 描述
startActivityAsync 根据指定操作启动 Android Activity。
openIOSSettings 打开 iOS 设置界面。
openApplication 通过包名打开应用。
getApplicationIconAsync 获取应用图标,返回 base64 编码的 PNG 字符串。

示例

startActivityAsync()

根据指定操作启动 Android Activity。

import { IntentLauncher, ActivityAction } from '@capgo/capacitor-intent-launcher';

// Open location settings
const result = await IntentLauncher.startActivityAsync({
  action: ActivityAction.LOCATION_SOURCE_SETTINGS
});

// Open a specific app settings
const result = await IntentLauncher.startActivityAsync({
  action: ActivityAction.APPLICATION_DETAILS_SETTINGS,
  data: 'package:com.example.app'
});

openIOSSettings()

打开 iOS 设置界面。

import { IntentLauncher, IOSSettings } from '@capgo/capacitor-intent-launcher';

// Open app settings (recommended - officially supported by Apple)
await IntentLauncher.openIOSSettings({ option: IOSSettings.App });

// Open WiFi settings (may not work in all iOS versions)
await IntentLauncher.openIOSSettings({ option: IOSSettings.WiFi });

openApplication()

通过包名打开应用。

import { IntentLauncher } from '@capgo/capacitor-intent-launcher';

// Open Gmail app
await IntentLauncher.openApplication({ packageName: 'com.google.android.gm' });

getApplicationIconAsync()

获取应用图标,返回 base64 编码的 PNG 字符串。

import { IntentLauncher } from '@capgo/capacitor-intent-launcher';

const { icon } = await IntentLauncher.getApplicationIconAsync({
  packageName: 'com.google.android.gm'
});
if (icon) {
  const img = document.createElement('img');
  img.src = icon;
}

完整参考文档

从“使用 @capgo/capacitor-intent-launcher”继续

如果你正在使用 使用 @capgo/capacitor-intent-launcher 要规划 dashboard 和 API 操作,请将其连接到 @capgo/capacitor-intent-launcher 有关 @capgo/capacitor-intent-launcher 中的实现细节, 快速入门 有关“入门指南”中的实现细节, API 概览 关于 API Overview 中的实现细节, 简介 关于简介中的实现细节,以及 API 密钥 关于 API Keys 中的实现细节。

常见问题

Intent Launcher 插件常见问题

如何在 Capacitor 应用中安装 Intent Launcher 插件?

运行 "bun add @capgo/capacitor-intent-launcher"(或 "npm install @capgo/capacitor-intent-launcher"),然后运行 "bunx cap sync",让 iOS 和 Android 项目获取原生 code。再在应用 code 中从 "@capgo/capacitor-intent-launcher" 导入。

@capgo/capacitor-intent-launcher 支持 React、Vue 和 Angular 吗?

支持。Intent Launcher 是一个 Capacitor 包,因此任何运行在 Capacitor 中的 Web 框架都能用,包括 Ionic、React、Vue、Angular、Svelte 和纯 JavaScript。

@capgo/capacitor-intent-launcher 支持哪个 Capacitor 版本?

Capgo 插件遵循 Capacitor 的主版本号:请使用与 Capacitor 主版本号一致的插件主版本(例如插件 v8 对应 Capacitor 8)。GitHub README 中的兼容性表列出了仍在维护的版本。

@capgo/capacitor-intent-launcher 是免费开源的吗?

是的。code 源码公开在 GitHub 上:https://github.com/Cap-go/capacitor-intent-launcher/,也可以从 npm 免费安装。欢迎提交 Bug 报告和 Pull Request。

我可以在不经过 App Store 审核的情况下,更新使用了 Intent Launcher 的 code 吗?

安装或升级插件会改动原生 code,因此需要重新做一次商店构建。之后,调用该插件的 JavaScript、HTML 和 CSS 改动就能通过 Capgo live updates 立即发布。

无需等待应用审核,即可发布 Intent Launcher 更新

只要插件已包含在你的商店版本中,Capgo live updates 就能在几分钟内把 JavaScript、HTML 和 CSS 的改动推送给用户。

开始使用 Capgo