[solved]Qt5.2beta + Java native... How to interface (QtAndroidExtras) ?



  • Hello!
    i'm testing to interface between Qt5.2beta-windows-android and Java native ..
    but it's very difficult to me. i'v tried various way.. i can not interface any more..
    Somebody help me please..
    build and deploy are ok. and then when run, error listed ..

    <QT PART>

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    //#include <QtTest/QtTest>
    #include <QtAndroidExtras/QAndroidJniObject>
    #include <QtAndroidExtras/QAndroidJniEnvironment>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
    , ui(new Ui::MainWindow)
    {

    ui->setupUi(this);
    /*if (!mActivitySet) {
        QJNIObjectPrivate::callStaticMethod<void>(bluetoothPlayerClass,
                                           "setActivity",
                                           "(Landroid/app/Activity;)V",
                                           QtAndroidPrivate::activity());
        mActivitySet = true;
    }*/
    

    }

    void MainWindow::on_pushButton_4_released()
    {

    QString number = QString::number(123);
    QAndroidJniObject parameter = QAndroidJniObject::fromString(number);
    jint returnValue = QAndroidJniObject::callStaticMethod<jint>("android/src/bluetooth/myBluetooth",
                                                          "parseInt",
                                                          "(Ljava/lang/String;)I",
                                                          parameter.object<jstring>());
    

    }

    jint JNICALL JNI_OnLoad(JavaVM *vm, void *)
    {

     JNIEnv *env; 
     if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_4) != JNI_OK) { 
        qFatal("Couldn't initialize environment!"); 
        return -1; 
     } 
    
     AndroidJNIBindings::detectNotificationClientClass(env); 
     return JNI_VERSION_1_4; 
    

    }

    jclass AndroidJNIBindings::m_notificationClientClass = 0;
    void AndroidJNIBindings::detectNotificationClientClass(JNIEnv *environment)
    {

    jclass clazz = environment->FindClass("android/src/bluetooth/myBluetooth"); 
    if (clazz == 0) { 
        environment->ExceptionDescribe(); 
        environment->ExceptionClear(); 
        return; 
    } 
    
    m_notificationClientClass = reinterpret_cast<jclass>(environment->NewGlobalRef(clazz)); 
    

    }

    <JAVA PART>
    package org.qtproject.example.adsb;
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.app.Activity;
    import android.bluetooth.BluetoothAdapter;
    import android.content.Context;
    import android.content.Intent;
    ...
    public class myBluetooth extends org.qtproject.qt5.android.bindings.QtActivity
    {

    private static final int REQUEST_ENABLE_BT = 0;

    private static final int REQUEST_DISCOVERABLE_BT = 0;
    
    private static final String TAG = "Qt Bluetooth";
    

    private static Context mApplicationContext = null;

    // Native callback functions for MediaPlayer

     //native public void onErrorNative(int what, int extra, long id);
    

    public static int parseInt(int s)

      {
    
    
            final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    
    
            mBluetoothAdapter.disable();
    
    
           return 1;
    
    
      }
    

    }



  • I'v found the cause.
    The package name and classname of callStaticMethod have to be matched..And then between qt and java, argument and return type are have to be matched.

    package org.qtproject.example.adsb;
    ::callStaticMethod<jint>(“android/src/bluetooth/myBluetooth”,
    --> ::callStaticMethod<jint>(“org.qtproject.example.adsb/myBluetooth"
    “(Ljava/lang/String;)I”,


Log in to reply
 

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