Android 上的 Cordova 应用程序 - 屏幕可能无法进入睡眠状态

Cordova app on Android - Screen may not go to sleep

我正在使用 cordova 为 Android 构建应用程序。此应用程序应 运行 全屏模式,屏幕可能永远不会关闭。我对安装了应用程序的设备具有完全的根控制权 - 所有设备都带有 Android 4.4 - 。

我设置了

Developer options -> Stay awake -> checked

并在

Display->Sleep

我设置的最高值是30分钟。这些设备都连接到它们的电源。

我的config.xml看起来像这样:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.project.name" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Project </name>
    <description>
      Project
    </description>
    <author email="my@email.com">
      Test
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
      <allow-intent href="market:*" />
      <splash src="res/screen/android/test.png" />
      <preference name="Fullscreen" value="true" />
      <preference name="KeepRunning" value="true"/>
      <preference name="InAppBrowserStorageEnabled" value="true"/>
      <preference name="LoadingDialog" value="Application is loading"/>
      <preference name="ErrorUrl" value="error.html"/>
      <preference name="LogLevel" value="VERBOSE"/>
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>

</widget>

我的问题是,在我在显示选项中设置的时间过后,屏幕变暗(不是完全关闭)。例如。屏幕亮了30分钟,之后确实亮了,但是背光很暗。

我该怎么做才能让屏幕保持明亮?

我找到了一个插件,对我有用:

cordova plugin add https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git

然后在 Javascript:

window.plugins.insomnia.keepAwake()

按预期工作,屏幕始终保持打开状态。