[SOLVED]How to keep the backlight on(Android)?



  • I develop android app with Qt 5.1.0 RC1.
    I want to keep the backlight on.

    @#include <android/native_activity.h>

    ANativeActivity *theActivity;
    ANativeActivity_setWindowFlags(theActivity,AWINDOW_FLAG_KEEP_SCREEN_ON,0);@

    but compile error:
    undefined reference to 'ANativeActivity_setWindowFlags'

    Someone can help me?
    thanks a lot.



  • You are missing some libraries in the .pro file probably.

    LIBS += -L$$PWD/../../android-ndk-r8d/platforms/android-14/arch-arm/usr/lib/ -landroid

    INCLUDEPATH += $$PWD/../../android-ndk-r8d/platforms/android-14/arch-arm/usr/include/android
    DEPENDPATH += $$PWD/../../android-ndk-r8d/platforms/android-14/arch-arm/usr/include/android

    You need to replace them with your corresponing directory. I hope that this is enough

    For the anative window flags you might need to include <window.h>



  • Thank you, Moster!

    If it can be useful to anyone, in my case (Qt 5.2.1, QtCreator 3.0.1, Android NDK, Revision 9c):

    1. I added the line "#include <android/window.h>".

    2. In QtCreator I edited the .pro file, in the editor section I clicked with the secondary button to make the contextual menu appear, I chose "Add Library...", I chose "System Library", I clicked on "Browse...", I chose the file [...]/android-ndk-r9c/platforms/android-19/arch-arm/usr/lib/libandroid.so
      I clicked on "Next", a dialog was shown saying "The following snippet will be added to [...]", I clicked on "Finish" and, finally, this line was added to the .pro file:

    unix|win32: LIBS += -landroid



  • By the way, about the code:
    @ANativeActivity *theActivity;
    ANativeActivity_setWindowFlags(theActivity,AWINDOW_FLAG_KEEP_SCREEN_ON,0);
    @
    I've been searching for this for several days :-( : Please, how can you obtain the pointer to the native activity running your Qt app?



  • I don't know how to obtain the pointer to the native activity running your Qt app.
    and that seems to be not necessary.

    I solved by add
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    on QtActivity.java



  • Thank you, Peterlin, that achieved the same result for me.

    Note: If someone uses Qt 5.2, modifies the QtActivity.java file and then that file is automatically overwritten, in my case it was very useful "that article":http://blog.qt.digia.com/blog/2013/12/12/implementing-in-app-purchase-on-android (people can search there the text "Next, I added a new Activity subclass") and "that example":http://qt-project.org/doc/qt-5/qtandroidextras-notification-example.html.


Log in to reply
 

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