代码之家  ›  专栏  ›  技术社区  ›  Michael B

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

  •  1
  • Michael B  · 技术社区  · 9 年前

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

    我已经设定好了

    Developer options -> Stay awake -> checked

    和in

    Display->Sleep

    我设置了最高值,即30分钟。这些设备都连接到电源上。

    我的 配置.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>
    

    我的问题是,在我在显示选项中设置的时间之后,屏幕会变暗(不是完全关闭)。E、 屏幕保持明亮30分钟,之后它确实保持亮起,但背光非常暗。

    我能做什么,让屏幕保持明亮?

    1 回复  |  直到 9 年前
        1
  •  10
  •   Michael B    8 年前

    我找到了一个插件,它为我提供了窍门:

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

    然后在Javascript中:

    window.plugins.insomnia.keepAwake()
    

    工作正常,屏幕始终打开。