Using @capgo/capacitor-keep-awake
Capacitor Keep Awake Plugin for preventing the device screen from dimming/sleeping.
Install
bun add @capgo/capacitor-keep-awake
bunx cap sync
bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.
Import
import { KeepAwake } from '@capgo/capacitor-keep-awake';
API at a glance
| Method | Description |
|---|---|
keepAwake |
Prevent the device from dimming the screen. |
allowSleep |
Allow the device to dim the screen (disable keep awake). |
isSupported |
Check if the keep awake feature is supported on the current platform. |
isKeptAwake |
Check if the device is currently being kept awake. |
Examples
keepAwake()
Prevent the device from dimming the screen.
import { KeepAwake } from '@capgo/capacitor-keep-awake';
await KeepAwake.keepAwake();
console.log('Screen will stay awake');
allowSleep()
Allow the device to dim the screen (disable keep awake).
import { KeepAwake } from '@capgo/capacitor-keep-awake';
await KeepAwake.allowSleep();
console.log('Screen can now dim');
isSupported()
Check if the keep awake feature is supported on the current platform.
import { KeepAwake } from '@capgo/capacitor-keep-awake';
const { isSupported } = await KeepAwake.isSupported();
if (isSupported) {
console.log('Keep awake is supported');
}
isKeptAwake()
Check if the device is currently being kept awake.
import { KeepAwake } from '@capgo/capacitor-keep-awake';
const { isKeptAwake } = await KeepAwake.isKeptAwake();
console.log('Is kept awake:', isKeptAwake);
Full reference
Keep going from Using @capgo/capacitor-keep-awake
If you are using Using @capgo/capacitor-keep-awake to plan native media and interface behavior, connect it with @capgo/capacitor-keep-awake for the implementation detail in @capgo/capacitor-keep-awake, Getting Started for the implementation detail in Getting Started, Using @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-live-activities, @capgo/capacitor-live-activities for the implementation detail in @capgo/capacitor-live-activities, and Using @capgo/capacitor-video-player for the native capability in Using @capgo/capacitor-video-player.