Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

All about Qt on Android

QtCon presentation


1 Comment

25 - Sept - 2019

Thad

void    keepScreenOn(bool   on) {
  static const int FLAG_KEEP_SCREEN_ON
    =   QAndroidJniObject::getStaticField( "android/view/WindowManager$LayoutParams", "FLAG_KEEP_SCREEN_ON" );

  QtAndroid::runOnAndroidThread([on, FLAG_KEEP_SCREEN_ON]   {
    auto window = QtAndroid::androidActivity().callObjectMethod("getWindow",
                                                        "()Landroid/view/Window;");
    if  (on)
      window.callMethod("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
    else
      window.callMethod("clearFlags",   "(I)V", FLAG_KEEP_SCREEN_ON);
  });   //ADDED Comma
}

error:
../src/example/MainWindow.cpp:76:38: error: 'FLAG_KEEP_SCREEN_ON' cannot be captured because it does not have automatic storage duration
  QtAndroid::runOnAndroidThread([on, FLAG_KEEP_SCREEN_ON]       {
                                     ^
../src/example/MainWindow.cpp:73:20: note: 'FLAG_KEEP_SCREEN_ON' declared here
  static const int FLAG_KEEP_SCREEN_ON