Getting Started
Dieser Inhalt ist in Ihrer Sprache noch nicht verfügbar.
-
Install the package
Terminal-Fenster npm i @capgo/capacitor-intent-launcherTerminal-Fenster pnpm add @capgo/capacitor-intent-launcherTerminal-Fenster yarn add @capgo/capacitor-intent-launcherTerminal-Fenster bun add @capgo/capacitor-intent-launcher -
Sync with native projects
Terminal-Fenster npx cap syncTerminal-Fenster pnpm cap syncTerminal-Fenster yarn cap syncTerminal-Fenster bunx cap sync
Import the plugin and use its methods to launch intents:
import { IntentLauncher, ActivityAction } from '@capgo/capacitor-intent-launcher';
// Open WiFi settingsconst openWifiSettings = async () => { await IntentLauncher.startActivityAsync({ action: ActivityAction.WIFI_SETTINGS });};
// Open location settingsconst openLocationSettings = async () => { await IntentLauncher.startActivityAsync({ action: ActivityAction.LOCATION_SOURCE_SETTINGS });};
// Open app details pageconst openAppSettings = async () => { await IntentLauncher.startActivityAsync({ action: ActivityAction.APPLICATION_DETAILS_SETTINGS, data: 'package:com.example.myapp' });};API Reference
Section titled “API Reference”startActivityAsync(options)
Section titled “startActivityAsync(options)”Start an Android activity for the given action.
interface IntentLauncherParams { action: string; // Activity action (use ActivityAction enum) category?: string; // Intent category className?: string; // Component class name data?: string; // URI data extra?: Record<string, unknown>; // Extra key-value data flags?: number; // Intent flags bitmask packageName?: string; // Component package name type?: string; // MIME type}
interface IntentLauncherResult { resultCode: ResultCode; // Result from activity data?: string; // Optional URI data returned extra?: Record<string, unknown>; // Optional extra data returned}
const result = await IntentLauncher.startActivityAsync({ action: ActivityAction.WIFI_SETTINGS});openApplication(options)
Section titled “openApplication(options)”Open an application by its package name.
interface OpenApplicationOptions { packageName: string;}
// Open Gmailawait IntentLauncher.openApplication({ packageName: 'com.google.android.gm'});getApplicationIconAsync(options)
Section titled “getApplicationIconAsync(options)”Get an application’s icon as base64-encoded PNG.
interface GetApplicationIconOptions { packageName: string;}
interface GetApplicationIconResult { icon: string; // base64 PNG with data:image/.png;base64, prefix}
const { icon } = await IntentLauncher.getApplicationIconAsync({ packageName: 'com.google.android.gm'});
// Use in img tag// <img src={icon} alt="App icon" />getPluginVersion()
Section titled “getPluginVersion()”Get the current plugin version.
const { version } = await IntentLauncher.getPluginVersion();Common Activity Actions
Section titled “Common Activity Actions”Settings Actions
Section titled “Settings Actions”import { IntentLauncher, ActivityAction } from '@capgo/capacitor-intent-launcher';
// Network settingsawait IntentLauncher.startActivityAsync({ action: ActivityAction.WIFI_SETTINGS });await IntentLauncher.startActivityAsync({ action: ActivityAction.BLUETOOTH_SETTINGS });await IntentLauncher.startActivityAsync({ action: ActivityAction.AIRPLANE_MODE_SETTINGS });await IntentLauncher.startActivityAsync({ action: ActivityAction.DATA_ROAMING_SETTINGS });
// Security settingsawait IntentLauncher.startActivityAsync({ action: ActivityAction.SECURITY_SETTINGS });await IntentLauncher.startActivityAsync({ action: ActivityAction.PRIVACY_SETTINGS });
// App settingsawait IntentLauncher.startActivityAsync({ action: ActivityAction.APPLICATION_SETTINGS });await IntentLauncher.startActivityAsync({ action: ActivityAction.MANAGE_APPLICATIONS_SETTINGS });
// Display & Soundawait IntentLauncher.startActivityAsync({ action: ActivityAction.DISPLAY_SETTINGS });await IntentLauncher.startActivityAsync({ action: ActivityAction.SOUND_SETTINGS });
// Locationawait IntentLauncher.startActivityAsync({ action: ActivityAction.LOCATION_SOURCE_SETTINGS });
// Batteryawait IntentLauncher.startActivityAsync({ action: ActivityAction.BATTERY_SAVER_SETTINGS });await IntentLauncher.startActivityAsync({ action: ActivityAction.IGNORE_BATTERY_OPTIMIZATION_SETTINGS });
// Notificationsawait IntentLauncher.startActivityAsync({ action: ActivityAction.APP_NOTIFICATION_SETTINGS });await IntentLauncher.startActivityAsync({ action: ActivityAction.NOTIFICATION_LISTENER_SETTINGS });Intent Actions
Section titled “Intent Actions”// View a URLawait IntentLauncher.startActivityAsync({ action: ActivityAction.VIEW, data: 'https://example.com'});
// Make a phone callawait IntentLauncher.startActivityAsync({ action: ActivityAction.DIAL, data: 'tel:+1234567890'});
// Send emailawait IntentLauncher.startActivityAsync({ action: ActivityAction.SENDTO, data: 'mailto:example@email.com'});
// Share textawait IntentLauncher.startActivityAsync({ action: ActivityAction.SEND, type: 'text/plain', extra: { 'android.intent.extra.TEXT': 'Hello from my app!' }});Complete Example
Section titled “Complete Example”import { IntentLauncher, ActivityAction, ResultCode} from '@capgo/capacitor-intent-launcher';import { Capacitor } from '@capacitor/core';
export class IntentService { private isAndroid = Capacitor.getPlatform() === 'android';
/** * Open app settings page for the current app */ async openAppSettings(packageName: string) { if (!this.isAndroid) { console.warn('Intent Launcher is Android-only'); return; }
await IntentLauncher.startActivityAsync({ action: ActivityAction.APPLICATION_DETAILS_SETTINGS, data: `package:${packageName}` }); }
/** * Open WiFi settings */ async openWifiSettings() { if (!this.isAndroid) return;
await IntentLauncher.startActivityAsync({ action: ActivityAction.WIFI_SETTINGS }); }
/** * Open location settings */ async openLocationSettings() { if (!this.isAndroid) return;
const result = await IntentLauncher.startActivityAsync({ action: ActivityAction.LOCATION_SOURCE_SETTINGS });
return result.resultCode === ResultCode.Success; }
/** * Request battery optimization exemption */ async requestBatteryExemption(packageName: string) { if (!this.isAndroid) return;
await IntentLauncher.startActivityAsync({ action: ActivityAction.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, data: `package:${packageName}` }); }
/** * Open another app */ async openApp(packageName: string) { if (!this.isAndroid) return;
try { await IntentLauncher.openApplication({ packageName }); } catch (error) { console.error(`App ${packageName} not installed or cannot be opened`); throw error; } }
/** * Get app icon for display */ async getAppIcon(packageName: string): Promise<string | null> { if (!this.isAndroid) return null;
try { const { icon } = await IntentLauncher.getApplicationIconAsync({ packageName }); return icon || null; } catch { return null; } }
/** * Share text content */ async shareText(text: string, title?: string) { if (!this.isAndroid) return;
await IntentLauncher.startActivityAsync({ action: ActivityAction.SEND, type: 'text/plain', extra: { 'android.intent.extra.TEXT': text, ...(title && { 'android.intent.extra.SUBJECT': title }) } }); }
/** * Open URL in browser */ async openUrl(url: string) { if (!this.isAndroid) return;
await IntentLauncher.startActivityAsync({ action: ActivityAction.VIEW, data: url }); }
/** * Open dialer with number */ async openDialer(phoneNumber: string) { if (!this.isAndroid) return;
await IntentLauncher.startActivityAsync({ action: ActivityAction.DIAL, data: `tel:${phoneNumber}` }); }
/** * Send email */ async composeEmail(to: string, subject?: string, body?: string) { if (!this.isAndroid) return;
const extra: Record<string, string> = {}; if (subject) extra['android.intent.extra.SUBJECT'] = subject; if (body) extra['android.intent.extra.TEXT'] = body;
await IntentLauncher.startActivityAsync({ action: ActivityAction.SENDTO, data: `mailto:${to}`, extra }); }}
// Usageconst intentService = new IntentService();
// Open settingsawait intentService.openWifiSettings();await intentService.openLocationSettings();
// Open another appawait intentService.openApp('com.google.android.gm');
// Get app iconconst icon = await intentService.getAppIcon('com.google.android.gm');
// Share contentawait intentService.shareText('Check out this app!', 'App Recommendation');Result Codes
Section titled “Result Codes”enum ResultCode { Success = -1, // Activity completed successfully Canceled = 0, // Activity was canceled FirstUser = 1 // Custom result code}Best Practices
Section titled “Best Practices”-
Check platform first
import { Capacitor } from '@capacitor/core';if (Capacitor.getPlatform() !== 'android') {console.warn('Intent Launcher is Android-only');return;} -
Handle errors for missing apps
try {await IntentLauncher.openApplication({packageName: 'com.example.app'});} catch (error) {// App not installedconsole.error('App not found');} -
Use proper URI format for app settings
// Correctdata: 'package:com.example.app'// Not correctdata: 'com.example.app'
Platform Notes
Section titled “Platform Notes”Android
Section titled “Android”- Full support for all intent actions
- Access to system settings and other apps
- Can receive result codes from activities
- Not supported - iOS does not have an equivalent to Android intents
- Use iOS-specific methods like opening Settings URL scheme
- Not supported - No intent system on web
Requirements
Section titled “Requirements”- Capacitor 8.0.0 or higher