使用 @capgo/capacitor-intent-launcher
Capacitor 意图启动器插件,用于在 Android 和 iOS 上启动 Android 意图和打开系统设置
安装
bun add @capgo/capacitor-intent-launcher
bunx cap sync
bunx cap sync 将插件的本机 code 复制到您的本机项目中。每次升级插件后,请重新运行它。
Import
import { IntentLauncher } from '@capgo/capacitor-intent-launcher';
API概览
| Method | 描述 |
|---|---|
startActivityAsync |
启动一个用于给定动作的 Android 活动。 |
openIOSSettings |
打开 iOS 设置屏幕。 |
openApplication |
打开一个通过包名识别的应用。 |
getApplicationIconAsync |
获取应用图标作为一个 base64 编码的 PNG 字符串。 |
示例
startActivityAsync()
启动一个用于给定动作的 Android 活动。
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-意图启动器
如果您正在使用 使用@capgo/capacitor-意图启动器 为了计划仪表板和API操作,连接它与 @capgo/capacitor-意图启动器 为了在@capgo/capacitor-意图启动器中实现详细信息 开始 为了在开始中实现详细信息 API概述 为了在API概述中实现详细信息 简介 简介中的实现细节 API 键 API 键中的实现细节