Capacitor plugin to enable background mode
This plugin replace to capacitor-plugin-background-mode
npm install @anuradev/capacitor-background-mode
npx cap syncBackground microphone access is disabled by default. To enable it, declare the
required permissions in the consuming application's AndroidManifest.xml:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />Request the microphone permission and enable the foreground service with:
await BackgroundMode.requestMicrophonePermission();
await BackgroundMode.enable({ allowMicrophoneInBackground: true });enable(...)disable()updateNotification(...)checkNotificationsPermission()requestNotificationsPermission()checkMicrophonePermission()requestMicrophonePermission()checkBatteryOptimizations()requestDisableBatteryOptimizations()enableWebViewOptimizations()disableWebViewOptimizations()moveToBackground()moveToForeground()isScreenOff()isEnabled()isActive()wakeUp()unlock()addListener('appInBackground', ...)addListener('appInForeground', ...)removeAllListeners()- Interfaces
- Type Aliases
enable(settings: Partial<ISettings>) => Promise<void>| Param | Type |
|---|---|
settings |
Partial<ISettings> |
disable() => Promise<void>updateNotification(settings: Partial<ISettings>) => Promise<void>| Param | Type |
|---|---|
settings |
Partial<ISettings> |
checkNotificationsPermission() => Promise<NotificationPermissionStatus>Returns: Promise<NotificationPermissionStatus>
requestNotificationsPermission() => Promise<NotificationPermissionStatus>Returns: Promise<NotificationPermissionStatus>
checkMicrophonePermission() => Promise<MicrophonePermissionStatus>Returns: Promise<MicrophonePermissionStatus>
requestMicrophonePermission() => Promise<MicrophonePermissionStatus>Returns: Promise<MicrophonePermissionStatus>
checkBatteryOptimizations() => Promise<{ enabled: boolean; }>Returns: Promise<{ enabled: boolean; }>
requestDisableBatteryOptimizations() => Promise<{ enabled: boolean; }>Returns: Promise<{ enabled: boolean; }>
enableWebViewOptimizations() => Promise<void>disableWebViewOptimizations() => Promise<void>moveToBackground() => Promise<void>moveToForeground() => Promise<void>isScreenOff() => Promise<{ isScreenOff: boolean; }>Returns: Promise<{ isScreenOff: boolean; }>
isEnabled() => Promise<{ enabled: boolean; }>Returns: Promise<{ enabled: boolean; }>
isActive() => Promise<{ activated: boolean; }>Returns: Promise<{ activated: boolean; }>
wakeUp() => Promise<void>unlock() => Promise<void>addListener(eventName: 'appInBackground', listenerFunc: () => void) => Promise<PluginListenerHandle>| Param | Type |
|---|---|
eventName |
'appInBackground' |
listenerFunc |
() => void |
Returns: Promise<PluginListenerHandle>
addListener(eventName: 'appInForeground', listenerFunc: () => void) => Promise<PluginListenerHandle>| Param | Type |
|---|---|
eventName |
'appInForeground' |
listenerFunc |
() => void |
Returns: Promise<PluginListenerHandle>
removeAllListeners() => Promise<void>| Prop | Type | Description | Default |
|---|---|---|---|
title |
string |
||
text |
string |
||
subText |
string |
||
bigText |
boolean |
||
resume |
boolean |
||
silent |
boolean |
||
hidden |
boolean |
||
color |
string |
||
icon |
string |
||
channelName |
string |
||
channelDescription |
string |
||
allowClose |
boolean |
||
closeIcon |
string |
||
closeTitle |
string |
||
showWhen |
boolean |
||
disableWebViewOptimization |
boolean |
||
allowMicrophoneInBackground |
boolean |
Allows the foreground service to use the microphone while the app is in the background. | false |
visibility |
'public' | 'private' | 'secret' |
| Prop | Type |
|---|---|
notifications |
PermissionState |
| Prop | Type |
|---|---|
microphone |
PermissionState |
| Prop | Type |
|---|---|
remove |
() => Promise<void> |
Make all properties in T optional
{
[P in keyof T]?: T[P];
}
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'