Search code examples
qtjava-native-interfaceqandroidjniobject

QT JNI , What is the difference between the callMetod and callStaticMetod


I can use QAndroidJniObject::callStaticMethod for static metod in java class.But I can't use callMethod , Is there an simple example for this.


Solution

  • Somthing like this:

    // get an android WallpaperManager using callStaticObjectMethod()
    QAndroidJniObject   activity = QtAndroid::androidActivity();
    QAndroidJniObject   context = activity.callObjectMethod("getApplicationContext", "()Landroid/content/Context;");
    QAndroidJniObject   wallpaperManager = QAndroidJniObject::callStaticObjectMethod("android/app/WallpaperManager", "getInstance", "(Landroid/content/Context;)Landroid/app/WallpaperManager;", context.object());
    
    // get width and height
    jint    w = wallpaperManager.callMethod<jint>("getDesiredMinimumWidth");
    jint    h = wallpaperManager.callMethod<jint>("getDesiredMinimumHeight");
    qDebug() << "Width:" << w << "Height:" << h;