让APP某一个页面保持屏幕常亮的方法


  • 船长

    https://git.merproject.org/mer-core/nemo-keepalive/tree/master

    有时候我们需要在某些页面让屏幕一直亮着,不要熄屏,这时候就需要它了

    • 添加依赖
      在spec或yaml中添加libkeepalive
    • 在qml中使用
    /* ------------------------------------------------------------------------- *
     * Copyright (C) 2014 Jolla Ltd.
     * Contact: Martin Jones <[email protected]>
     * License: BSD
     * ------------------------------------------------------------------------- */
    import QtQuick 2.0
    import Sailfish.Silica 1.0
    import Nemo.KeepAlive 1.1
    ApplicationWindow {
        property var startTime
        property var currentTime
        initialPage: Component {
            Page {
                KeepAlive {
                    id: keepAlive
                }
                Timer {
                    id: timer
                    property int count
                    interval: 1000
                    repeat: true
                    onTriggered: {
                        ++count
                        currentTime = new Date()
                    }
                }
                Column {
                    width: parent.width
                    spacing: Theme.paddingLarge
                    anchors.centerIn: parent
                    TextSwitch {
                        text: "Keep Alive"
                        anchors.horizontalCenter: parent.horizontalCenter
                        onCheckedChanged: {
                            startTime = new Date()
                            currentTime = new Date()
                            timer.count = 0
                            timer.restart()
                            keepAlive.enabled = checked
                        }
                    }
                    Label {
                        anchors.horizontalCenter: parent.horizontalCenter
                        text: "Duration: " + Math.round((currentTime.getTime() - startTime.getTime())/1000)
                    }
                    Label {
                        anchors.horizontalCenter: parent.horizontalCenter
                        text: "Timer triggered: " + timer.count
                    }
                }
                Component.onCompleted: {
                    startTime = new Date()
                    currentTime = new Date()
                    timer.start()
                }
            }
        }
    }
    

  • 大副

    也许该试着学学qml了……?


  • 船长

    @天苯 可以学学,这东西跨平台,写客户端界面首选


Log in to reply
 

登录后则不再显示广告,广告收入仅用于网站运营!您如果不想注册登录则可以通过广告屏蔽扩展进行屏蔽。

After logging in, the ads are no longer displayed, and the advertising revenue is only used for website operations! If you don't want to sign up, you can block it with the ad block plugin.