Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED]How to keep the backlight on(Android)?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 3 Posters 4.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peterlin82
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Moster
      wrote on last edited by
      #2

      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>

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Ganton
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Ganton
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • P Offline
            P Offline
            peterlin82
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Ganton
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved