Installing Community Plugins

Installing and Configuring a Community Plugin

A reader with the phone propped against a teapot wants the screen to stay on. @capacitor-community/keep-awake passed the check of Vetting Community Plugins and installs like an official plugin:

Adding keep-awake to BookNestShell
npm install @capacitor-community/keep-awake
npx cap sync android
grep -n keep-awake android/capacitor.settings.gradle android/app/capacitor.build.gradle
Output
...
[info] Found 16 Capacitor plugins for android:
       @capacitor-community/keep-awake@8.0.1
...
[info] Sync finished in 0.352s
android/capacitor.settings.gradle:5:include ':capacitor-community-keep-awake'
android/capacitor.settings.gradle:6:project(':capacitor-community-keep-awake').projectDir =
  new File('../node_modules/@capacitor-community/keep-awake/android')
android/app/capacitor.build.gradle:12:    implementation
  project(':capacitor-community-keep-awake')

cap sync wired it in as a Gradle 19,597 module (Surviving cap sync). An Awake button in the lab toggles it:

Toggling keep-awake in src/js/lab.jsJavaScript
export async function reading() {
  const { isKeptAwake } = await KeepAwake.isKeptAwake();
  if (isKeptAwake) await KeepAwake.allowSleep();
  else await KeepAwake.keepAwake();
  return show('reading', await KeepAwake.isKeptAwake());
}

The plugin's Java code adds FLAG_KEEP_SCREEN_ON to the activity's window, and the window manager shows it. After the first tap, then after the second:

Counting windows that keep the screen onShell
adb -s emulator-5558 shell dumpsys window windows | grep -c KEEP_SCREEN_ON
Output
1
0

Keep-awake needs no configuration or permission. Plugins that do take settings where official ones do: runtime options in the plugins block of capacitor.config.ts (Plugin Configuration), Android permissions and SDK versions in AndroidManifest.xml and variables.gradle, and iOS usage strings in Info.plist. Permissions in the plugin's own manifest merge automatically (Official Plugins), but there is no plugin.xml (plugin.xml Wiring) to edit anything else, so apply what the README asks for by hand and commit it.