Search code examples
androidc++qtqandroidjniobject

Unable to create WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON object using QAndroidJniObject


Here is my code, trying to create a QAndroidJniObject to access WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON value.

So I do this:

QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
if ( activity.isValid() )
{
    jint keepAliveField = QAndroidJniObject::getStaticField<jint>("android/view/WindowManager/LayoutParams","FLAG_KEEP_SCREEN_ON");

    qDebug() << "keepAliveField=" << keepAliveField;
}

Any idea why this prints keepAliveField=0when I expect keepAliveField=128?


Solution

  • The class is WindowManager.LayoutParams, just replace the '.' with '$'

    QAndroidJniObject::getStaticField<jint>(
                "android/view/WindowManager$LayoutParams", "FLAG_KEEP_SCREEN_ON");