使用 @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 中的实现细节。