I'm trying to execute a java file inside qt, here is my java file code:
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
public class Main extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
The question is how this java file can be called, I'm confused & don't know how to call the function onUpdate, Any ideas ?
To run Java code in your Qt Android application you should use the Qt Android Extras module which contains additional functionality for development on Android.
You can use JNI to call a Java function from C/C++ or callback a C/C++ function from Java.
Let's consider you have a static Java method like :
package com.MyApp;
public class JavaClass
{
public static int SomeMethod(int n)
{
...
}
}
First you need to add this to your .pro file :
QT += androidextras
And Include the relevant header file :
#include <QAndroidJniObject>
You can then call a static java function from your C++ code like :
bool retVal = QAndroidJniObject::callStaticMethod<jint>
("com/MyApp/JavaClass" // class name
, "SomeMethod" // method name
, "(I)I" // signature
, val);
For a more detailed explanation you can see this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With