跳转到正文

快速入门

GitHub

你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:

终端窗口
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

然后使用以下 prompt:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-intent-launcher` plugin in my project.

如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:

终端窗口
bun add @capgo/capacitor-intent-launcher
bunx cap sync
import { IntentLauncher } from '@capgo/capacitor-intent-launcher';
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'
});
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 });
import { IntentLauncher } from '@capgo/capacitor-intent-launcher';
// Open Gmail app
await IntentLauncher.openApplication({ packageName: 'com.google.android.gm' });
  • 原生同步:运行 bunx cap sync 在插件升级后。
  • 唯一可信来源:信任 src/definitions.ts 在 GitHub 仓库中。

针对指定的 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'
});

打开 iOS 设置界面。

注意:Apple 官方唯一支持的选项是 App 这会打开您应用的设置页面。 其他选项可能有效,但不保证稳定性,可能会在未来的 iOS 版本中失效,或导致 App Store 审核被拒。

另外请注意,iOS Simulator 有时只会打开 Settings 应用,而不是指定的选项。

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

通过包名打开应用程序。

import { IntentLauncher } from '@capgo/capacitor-intent-launcher';
// Open Gmail app
await IntentLauncher.openApplication({ packageName: 'com.google.android.gm' });

获取以 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;
}

启动 Activity 的配置选项。

export interface IntentLauncherParams {
/**
* The action to perform. Use values from `ActivityAction` enum.
*
* @since 1.0.0
*/
action: string;
/**
* Optional category to add to the intent.
*
* @since 1.0.0
*/
category?: string;
/**
* Optional class name for the component to launch.
*
* @since 1.0.0
*/
className?: string;
/**
* Optional URI data for the intent. Must be a valid URI.
*
* @since 1.0.0
*/
data?: string;
/**
* Optional extra data to pass to the intent as key-value pairs.
*
* @since 1.0.0
*/
extra?: Record<string, unknown>;
/**
* Optional intent flags as a bitmask.
*
* @since 1.0.0
*/
flags?: number;
/**
* Optional package name for the component.
*
* @since 1.0.0
*/
packageName?: string;
/**
* Optional MIME type for the intent data.
*
* @since 1.0.0
*/
type?: string;
}

启动 Activity 的返回结果。

export interface IntentLauncherResult {
/**
* The result code returned by the activity.
*
* @since 1.0.0
*/
resultCode: ResultCode;
/**
* Optional data URI returned by the activity.
*
* @since 1.0.0
*/
data?: string;
/**
* Optional extra data returned by the activity.
*
* @since 1.0.0
*/
extra?: Record<string, unknown>;
}

打开 iOS 设置的配置选项。

export interface IOSSettingsParams {
/**
* The iOS settings screen to open. Use values from `IOSSettings` enum.
*
* @since 8.2.0
*/
option: string;
}

打开 iOS 设置后的结果。

export interface IOSSettingsResult {
/**
* Whether the settings screen was successfully opened.
*
* @since 8.2.0
*/
success: boolean;
}

打开应用程序的相关选项。

export interface OpenApplicationOptions {
/**
* The package name of the application to open.
*
* @since 1.0.0
*/
packageName: string;
}

获取应用程序图标的相关选项。

export interface GetApplicationIconOptions {
/**
* The package name of the application.
*
* @since 1.0.0
*/
packageName: string;
}

获取应用程序图标后的结果。

export interface GetApplicationIconResult {
/**
* The application icon as a base64-encoded PNG string prefixed with 'data:image/.png;base64,'.
* Empty string if the icon is not available.
*
* @since 1.0.0
*/
icon: string;
}

Activity 返回的结果码。

export enum ResultCode {
/**
* The activity completed successfully.
*/
Success = -1,
/**
* The activity was canceled by the user.
*/
Canceled = 0,
/**
* First custom user-defined result code.
*/
FirstUser = 1,
}

本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。

如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-intent-launcher 在使用 @capgo/capacitor-intent-launcher 时,若需调用原生能力, API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。