Home > Enterprise >  How do I configure Android settings in a Vue/Capacitor app?
How do I configure Android settings in a Vue/Capacitor app?

Time:06-24

I'm building an application for web/Android with Vue Capacitor. What's the correct way to manipulate the Android part? For example, I'd like the screen to not turn off through idle. Apparently, the way to do this is to put getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); in the MainActivity. But since the Android part gets built again all the time it doesn't really make sense to edit it directly (or maybe I'm mistaken here somehow?)

So how do I achieve something like this?

CodePudding user response:

You can just use this community plugin: https://github.com/capacitor-community/keep-awake. This way you don't have to change the native code.

import { KeepAwake } from '@capacitor-community/keep-awake';

const keepAwake = async () => {
  await KeepAwake.keepAwake();
};

const allowSleep = async () => {
  await KeepAwake.allowSleep();
};

CodePudding user response:

Once you run npx cap add android, the native project gets created and it’s never modified by capacitor, so you can make any changes you want in the MainActivity.java file or any other files (except the ones that start with “automatically generated, do not edit” or similar messaging).

  • Related