指南
关于意图启动器的教程
使用 @capgo/capacitor-intent-launcher
Capacitor 的意图启动器插件,用于在安卓和 iOS 上启动安卓意图和打开系统设置
安装
bun add @capgo/capacitor-intent-launcher
bunx cap sync
此插件暴露的内容
startActivityAsync- 启动一个给定动作的 Android 活动。openIOSSettings- 打开 iOS 设置屏幕。openApplication- 打开一个应用程序的包名。getApplicationIconAsync- 以 base64 编码的 PNG 字符串形式获取应用程序图标。
示例使用
startActivityAsync
启动一个给定动作的 Android 活动。
import { IntentLauncher } 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 } 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;
}
全局参考
- GitHub: https://github.com/Cap-go/capacitor-intent-launcher/
- 文档:/docs/plugins/intent-launcher/
继续使用@capgo/capacitor-intent-launcher
如果您正在使用 使用@capgo/capacitor-intent-launcher 来规划仪表板和API操作,连接它与 @capgo/capacitor-intent-launcher 了解@capgo/capacitor-intent-launcher的实现细节在@capgo/capacitor-intent-launcher中 入门 了解入门的实现细节在入门中 API概述 对于API概述的实现细节 简介 对于简介的实现细节 API密钥 对于API密钥的实现细节