Control screen luminosity



  • I have an application which scrolls automatically some data in a listview, without user action. After about 30 seconds the screen luminosity goes at half value and after another 30 seconds the screen goes off. I'd like to be able to prevent this from the application. From what I searched so far it seems it has to do with the screensaver, but Qt5.3 (that I am using) has no suport for controlling the screensaver.



  • What kind of device is this? Android, iOS, some other embedded device?

    If you can set the power settings on the screen to stay awake at all times, then I think you can fix it. On android at least you can prevent the screen to sleep. On embedded devices you write your own driver to do this or just set some settings on existing driver.

    However, this is not related to QtQuick.



  • It's an Android phone. My problem is I don't want to alter the power settings from the phone settings menu, I would like to do it from the app, so I can stop power saving when the app starts and restore it before the app closes.



  • Ok, then you should take a look at this:

    Permission you need to change power settings:
    http://developer.android.com/reference/android/Manifest.permission.html#WAKE_LOCK

    Java method to change power settings:
    http://developer.android.com/reference/android/os/PowerManager.WakeLock.html

    Example of using C++ to access Java in a Qt application:
    http://doc-snapshot.qt-project.org/qt5-5.3/qtandroidextras-notification-example.html



  • Thank you very much, I'll give it a try.



  • Try to add this new method on example qtandroidextras-notification-example in the file NotificationClient.java

    @
    public static void keepScreenOn() {
    Window w = m_instance.getWindow();
    if ( w == null ) {
    Log.v(TAG, "null window");
    } else {
    w.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
    }
    @

    Add these imports in the file NotificationClient.java
    @
    import android.view.WindowManager;
    import android.view.Window;
    import android.util.Log;
    @

    Call it in main.cpp just after QGuiApplication.
    @
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/notification/NotificationClient",
    "keepScreenOn");@

    I tried to add it after line
    @QQuickView view;@

    and after line

    @view.show();@

    but it not works for me.



  • Try to add this new method on example qtandroidextras-notification-example in the file NotificationClient.java

    @
    public static void keepScreenOn() {
    Window w = m_instance.getWindow();
    if ( w == null ) {
    Log.v(TAG, "null window");
    } else {
    w.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
    }
    @

    Add these imports in the file NotificationClient.java
    @
    import android.view.WindowManager;
    import android.view.Window;
    import android.util.Log;
    @

    Call it in main.cpp just after QGuiApplication.
    @
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/notification/NotificationClient",
    "keepScreenOn");@

    I tried to add it after line
    @QQuickView view;@

    and after line

    @view.show();@

    but it not works for me.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.