跳转至正文

Intent Launcher Capacitor 插件

通过 Intent 系统启动 Android 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 intents 并打开系统设置。

安装

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

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

导入

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

API 概览

方法 描述
startActivityAsync 针对指定的 Action 启动 Android Activity。
openIOSSettings 打开 iOS 设置界面。
openApplication 通过包名打开应用程序。
getApplicationIconAsync 获取以 base64 编码的 PNG 字符串形式的应用图标。

示例

startActivityAsync()

针对指定的 Action 启动 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 项目同步 native 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 立即发布。

无需等待 App Store 审核,即可快速发布 Intent Launcher 的变更

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

开始使用 Capgo