@capacitor-community/keep-awake
Capacitor community plugin to prevent your screen from getting some sleep!
Maintainer | GitHub | Social |
---|---|---|
Kevin Boosten | boosten | @Boostuh1 |
npm i @capacitor-community/keep-awake
No extra steps required 🙂.
You have to register your plugin in your app main activity. See official Capacitor docs
import com.getcapacitor.community.keepawake.KeepAwake;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {
{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(KeepAwake.class);
}
}
);
}
}
import { Plugins } from '@capacitor/core';
@Component({
template: `
<button (click)="keepAwake()">keep awake!</button>
<button (click)="allowSleep()">let me sleep!</button>
`,
})
export class AppComponent {
async keepAwake() {
await Plugins.KeepAwake.keepAwake();
}
async allowSleep() {
await Plugins.KeepAwake.allowSleep();
}
}
Capacitor version of the plugin: cordova insommia.